views:
107answers:
5just add index.html with:
<meta http-equiv="Refresh" content="0; http://www.example.com">
You might want to check with your domain name provider. You should be able to configure your hosting to automatically redirect from nextech.pk to www.nextech.pk.
But you could also do it in Global.asax or with an IHttpModule in the BeginRequest handler:
private void context_BeginRequest(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication) sender;
if (!application.Request.Url.ToString().Contains("http://www."))
{
application.Response.Redirect(
application.Request.Url.ToString().Replace("http://", "http://www."));
}
}
Both of these methods would work with any request on your website.
It will be there as an option in the domain settings page where your domain is registered. use nextech.pk or www.nextech.pk or both something like that.
Changing there will be the easy one.
In the base page for your website or your Default.aspx file, check if the request url is prefixed with www. Otherwise redirect using Response.Redirect to the url prefixed with www.
I don't do this at the ASP.NET level, as it would fail on static content such as images. Simply add an additional website to IIS, with the host header value of all the URLs you wish to redirect FROM (e.g. example.com). On the "Home Directory" tab, click on "A redirection to a URL", and enter the URL you wish to redirect TO.
This allows you to enter http://example.com/foo.txt and end up at http://www.example.com/foo.txt
(NB. These instructions are for IIS 6, they'll vary slightly for IIS 7).