I was working on a Website which was earlier built with ASP.NET Web Forms and now is built with ASP.NET MVC.
We made the new MVC version live last week.
But the old login url which is www.website.com/login.aspx has been bookmarked by many users and they still use that and hence they get 404 errors.
So I was wondering which would be the easiest and best way to redirect the user from the old url to the new mvc url which is www.website.com/account/login
Like this login url, I am expecting the users may have bookmarked few other urls also, so what will be the best way to handle this ?
You could use the URL Rewrite module
in IIS. It's as simple as putting the following rule in your <system.webServer>
section:
<system.webServer>
<rewrite>
<rules>
<rule name="Login page redirect" stopProcessing="true">
<match url="login.aspx" />
<action type="Redirect" redirectType="Permanent" url="account/login" />
</rule>
</rules>
</rewrite>
...
</system.webServer>
The module is very powerful and allows you any kind of rewrites and redirects. Here are some other sample rules
.
in the global.asax
void Application_BeginRequest(Object source, EventArgs e)
{
//HttpApplication app = (HttpApplication)source;
//HttpContext context = app.Context;
string reqURL = HttpContext.Current.Request.Url;
if(String.compare(reqURL, "www.website.com/login.aspx")==0)
{
Response.Redirect("www.website.com/account/login");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With