Default.aspx not running in an ASP.NET project with MVC sections

My application is basically an ASP.NET application into which I am adding an MVC section.

My Default.aspx (no codebehind) page has a simple Response.Redirect on the StartPage.aspx page, but for some reason MVC is capturing and I don't get to the StartPage.aspx page. Instead, I am redirected to my first and only part of MVC, which is the registered path that I registered on the global.asax.cs (Albums) page.

Is there any way to tell MVC to leave my requests to the root "/" by my default IIS 7 document ... in this case Default.aspx?

This is what is in my RegisterRoutes:

routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute("Albums","{controller}/{action}/{id}", new { controller = "Albums", action = "Index", id = "" }); 
+7
asp.net-mvc
source share
3 answers

If you remove the default controller from your second route there, it will no longer match "/", and Routing will ignore requests for "/", leaving them for the normal ASP.Net pipeline to handle

So, change your routes to:

 routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute("Albums","{controller}/{action}/{id}", new { action = "Index", id = "" }); 

This should solve your problem!

+7
source share

The default.aspx page is served by IIS because it is the default document. MVC, let the default.aspx page process the request if it understood that the request was for default.aspx (for example, "http://foo.com/default.aspx"). This does not affect this, although in this scenario ("http://foo.com"), so that you can add this to the default route to achieve what you are after

 // ignore "/" routes.IgnoreRoute(""); // default route routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults ); 
+1
source share

You can tell MVC to ignore Default.aspx as follows:

 routes.IgnoreRoute("Default.aspx"); 
0
source share

All Articles