How can I response redirect from http://domain.com to http://www.domain.com? Code, not Web.config, which doesn't seem to work for me.
A:
Use a 301 redirect to the correct url. Something like this;
Response.StatusCode = (int)HttpStatusCode.MovedPermanently;
Response.RedirectLocation = "http://www.domain.com";
Rob
2010-09-10 09:08:53
because its the same page it keeps looping
maggie
2010-09-10 14:12:10
Can you show us the code of how you implemented it now? Try adding a return null
Rob
2010-09-10 14:25:08
+6
A:
If you are hosting in IIS, then you can set up a HTTP redirect.
Information about 301 redirects
EDIT
You could add the following to your Page_Load method:
// Check if page is running under theperfectfajita.com. If not redirect ...
if (!HttpContext.Current.Request.Url.Host.Contains("localhost"))
{
if (HttpContext.Current.Request.Url.Host.CompareTo("domain.com") != 0)
{
HttpContext.Current.Response.Redirect("http://www.domain.com" + Context.Request.Url.PathAndQuery);
}
}
Ardman
2010-09-10 09:24:06