0

I'm not so sure how ask this, but here's.

I bought a domain let's called foo.com and I develop an application in .net with mvc3 framework also I have in my server a trusted ssl by Thawthe but only work's with www.foo.com. Now what I want it's always redirect all my users from foo.com to www.foo.com.

How can I do this? with a dns enter? if this the answer could you provide an example?.

Or do I need to add some code let's say in the global.asax in some evet check url provided in the request of the user ahd redirected to what I wanted?.

Could be a configuration that could be added in the web.config?

My application it's manage by a dot net panel provided by a host seller

Jorge
  • 17,896
  • 19
  • 80
  • 126
  • I've answered similar question 2 days ago, you can look at here - http://stackoverflow.com/questions/13501226/domain-name-changes-how-to-redirect-with-asp-mvc-4/13503349#13503349 – Koste Nov 24 '12 at 20:08

1 Answers1

1

Here is an example for you. You can add to the following to your Global.asax and it should do the trick:

void Application_BeginRequest(object sender, EventArgs e)
    {
        if (HttpContext.Current.Request.Url.ToString().ToLower().Contains
          ("http://foo.com"))
        {
            HttpContext.Current.Response.Status = "301 Moved Permanently";
            HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString()
              .ToLower().Replace("http://foo.com",
              "http://www.foo.com"));
        }
    }

You can reference http://blueonionsoftware.com/blog.aspx?p=69139a7a-f47d-47c0-9f8e-9112b4131006 for more information.

Sean Keating
  • 1,718
  • 14
  • 28