Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 692559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:39:48+00:00 2026-05-14T02:39:48+00:00

Due to a prinitng error in some promotional material I have a site that

  • 0

Due to a prinitng error in some promotional material I have a site that is receiving a lot of requests which should be for one site arriving at another.
i.e.
The valid sites are http://site1.com/abc & http://site2.com/def but people are being told to go to http://site1.com/def.

I have control over site1 but not site2.

site1 contains logic for checking that the first part of the route is valid in an actionfilter, like this:

public override void OnActionExecuting(ActionExecutingContext filterContext)
{
    base.OnActionExecuting(filterContext);

    if ((!filterContext.ActionParameters.ContainsKey("id")) 
     || (!manager.WhiteLabelExists(filterContext.ActionParameters["id"].ToString())))
    {
        if (filterContext.ActionParameters["id"].ToString().ToLowerInvariant().Equals("def"))
        {
            filterContext.HttpContext.Response.Redirect("http://site2.com/def", true);
        }

        filterContext.Result = new ViewResult { ViewName = "NoWhiteLabel" };
        filterContext.HttpContext.Response.Clear();
    }
}

I’m not sure how to test the redirection to the other site though.
I already have tests for redirecting to “NoWhiteLabel” using the MvcContrib Test Helpers, but these aren’t able to handle (as far as I can see) this situation.

How do I test the redirection to antoher site?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:39:49+00:00Added an answer on May 14, 2026 at 2:39 am

    I would recommend you using RedirectResult instead of calling Response.Redirect:

    if (youWantToRedirect) 
    {
        filterContext.Result = new RedirectResult("http://site2.com/def")
    }
    else
    {
        filterContext.Result = new ViewResult { ViewName = "NoWhiteLabel" };
    }
    

    Now if you know how to test ViewResult with MVCContrib TestHelper you will be able to test the RedirectResult the same way. The tricky part is mocking the manager to force it to satisfy the if condition.


    UPDATE:

    Here’s how a sample test might look like:

        // arrange
        var mock = new MockRepository();
        var controller = mock.StrictMock<Controller>();
        new TestControllerBuilder().InitializeController(controller);
        var sut = new MyFilter();
        var aec = new ActionExecutingContext(
            controller.ControllerContext, 
            mock.StrictMock<ActionDescriptor>(), 
            new Dictionary<string, object>());
    
        // act
        sut.OnActionExecuting(aec);
    
        // assert
        aec.Result.ShouldBe<RedirectResult>("");
        var result = (RedirectResult)aec.Result;
        result.Url.ShouldEqual("http://site2.com/def", "");
    

    Update (By Matt Lacey)
    Here’s how I actually got this working:

        // arrange
        var mock = new MockRepository();
        // Note that in the next line I create an actual instance of my real controller - couldn't get a mock to work correctly
        var controller = new HomeController(new Stubs.BlankContextInfoProvider(), new Stubs.BlankWhiteLabelManager());
        new TestControllerBuilder().InitializeController(controller);
        var sut = new UseBrandedViewModelAttribute(new Stubs.BlankWhiteLabelManager());
    
        var aec = new ActionExecutingContext(
            controller.ControllerContext,
            mock.StrictMock<ActionDescriptor>(),
            // being sure to specify the necessary action parameters
            new Dictionary<string, object> { { "id", "def" } });
    
        // act
        sut.OnActionExecuting(aec);
    
        // assert
        aec.Result.ShouldBe<RedirectResult>("");
        var result = (RedirectResult)aec.Result;
        result.Url.ShouldEqual("http://site2.com/def", "");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Due to repetitive errors with one of our Java applications: Engine engine_0: Error in
Due to an architecture I must work with that likely breaks a lot of
I have a FlowDocument that varies in height due to an ItemsControl in a
Due to company constraints out of my control, I have the following scenario: A
I have a native Delphi TFrame that emulates Roy Tanck's Cumulus Tag Cloud viewer,
Due to some caching issues, I need to explicitly bypass the cache, for a
I have the following code in my Ajax, which executes a page reload function
I have seen some elegant solutions on fetching the parents document from iframe -
I have an SNMP trap application in Java that aims at listening to an
We've got an app with some legacy printer setup code that we are still

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.