3

I want to have on my existing IIS web site an additional host header that will always redirect url's that come in with that domain to a specific mvc razor view page. I've updated my global.asax as follows which kind of works but feels awkward and changes the URL to show the new URL which I don't want.

That is, I want all reqeusts that come in on the domain foo.org to redirect to the view /giving/svccgiving and for the users browser to continue to say foo.org

Here is the code I tried that partially works. any better suggestions?

protected void Application_BeginRequest(object sender, EventArgs e)
{
    if (Request.Url.AbsoluteUri.ToLower().Contains("foo.org") &&
        !Request.Url.AbsoluteUri.ToLower().Contains("giving/svccgiving"))
    {
        Response.Redirect("~/Giving/SVCCGiving");
    }
}
Agustin Meriles
  • 4,866
  • 3
  • 29
  • 44
Peter Kellner
  • 14,748
  • 25
  • 102
  • 188
  • have you tried playing with routes instead? – Sinaesthetic Apr 26 '14 at 16:47
  • I've thought about route, but I don't think that at the time the routes are established, there is any visibility of what domain is coming in. That I believe is only known at the start of the request (I could be wrong) – Peter Kellner Apr 26 '14 at 16:50
  • Maybe this will help http://stackoverflow.com/questions/278668/is-it-possible-to-make-an-asp-net-mvc-route-based-on-a-subdomain – Sinaesthetic Apr 26 '14 at 17:01

1 Answers1

1

The following works fine for me,

this.Response.Redirect("~/Giving/SVCCGiving", true);

because, the response end is true so further processing of the request does not take place

Saravanan
  • 7,637
  • 5
  • 41
  • 72