Redirecting .asp to aspx in ASP.Net MVC

I am learning ASP.Net MVC and I am loving it.

In the process of migrating our existing classic asp website to ASP.Net MVC we realized that we would still need an .asp file as part of the web app. It’s the redirect.asp file that all our products call to go to different parts of our website.

Fortunately, ASP.Net MVC provides a neat way to do this without actually creating an .asp file. You can route the .asp call to .aspx (MVC View) and have all your code in ASP.Net MVC controller.

Go to Global.asax.cs and write the following code:

routes.MapRoute("Redirect", "redirect.asp", new { controller = "Home", action = "Redirect" });

That’s it.

Note that the redirect.asp file should not (and does not) exist. The routing engine would just route the call to an action that you specify.


One thought on “Redirecting .asp to aspx in ASP.Net MVC”

Leave a Reply

Your email address will not be published. Required fields are marked *