tags:

views:

391

answers:

2

My app is mainly an ASP.NET app that I'm adding an MVC section to it.

My Default.aspx (no codebehind) page has a simple Response.Redirect to a StartPage.aspx page but for some reason MVC is taking over and I'm not getting to the StartPage.aspx page. Instead I get routed over to my first and only MVC section which is a registered route that I've registered in the global.asax.cs page (Albums).

Is there a way to tell MVC to leave my requests to the root "/" to be my IIS 7 default 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 = "" });

+1  A: 

If you remove the default controller from your second route there, it won't match against "/" anymore and Routing will ignore requests for "/", leaving them for the usual 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 = "" });

That should solve your problem!

anurse
Your suggestion worked but I'm wondering if it is better to ignore the default.aspx page like Alconja mentions? In the future as I create more MVC routes I won't be able to specify a default controller or am I misunderstanding what specifying the {controller} means? I figured it was specific to "Albums" but I'm not sure. Thanks.
Mouffette
I'm not sure if Alconja's solution will actually work in the "/" case. Since the URL arriving is "/" rather than "/Default.aspx". It depends on when the Default Document is applied. The only reason to specify a default controller value is so that requests to "/" get routed to that controller, but if you want your Default.aspx page to handle requests to "/", you should NOT have a default controller
anurse
+1  A: 

You could tell the MVC to ignore the Default.aspx like this:

routes.IgnoreRoute("Default.aspx");
Alconja