URL redirection in ASP.NET MVC

I was working on a site that was previously created using ASP.NET Web Forms and is now built with ASP.NET MVC.

We released a new version of MVC last week.

But the old login URL, which www.website.com/login.aspx has been noted by many users, and they still use it and therefore get 404 errors.

So, I was wondering which one 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 expect users to bookmark several other URLs, so what would be the best way to handle this?

+4
source share
2 answers

You can use the URL Rewrite module in IIS. It is as simple as <system.webServer> following rule in the <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 to rewrite and redirect. Here are a few other sample rules .

+6
source

in 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"); } } 
+5
source

All Articles