Mixing ASP.NET MVC in ASP.NET WebForms

For some reason, my routing ignores any attempt to access my MVC pages and just gives me 404s. I have a WebForms application configured as follows:

Virtual Directory: item

Therefore, I usually access my site like this:

The original structure of my ASP.NET WebForms application reflects the file system, so I have folders filled with .aspx files, and I need to use them. For some reason, when I try to access a page using MVC routing, for example:

I just get 404 error. I used ASP.NET MVC myself, and I know that even if I had not configured my folders correctly, I would not have gotten 404. I would have gotten the reasons why this page was not found, and hints where should the files be. The following is routing information. Where am I mistaken?

public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.IgnoreRoute("{resource}.aspx/{*pathInfo}"); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" } // Parameter defaults ); } protected void Application_Start() { RegisterRoutes(RouteTable.Routes); } 
+6
asp.net-mvc iis asp.net-mvc-routing
source share
1 answer

Can you tell me which OS you are running on, and is this site running under the VS.NET Web Dev or IIS server?

Routing in MVC routes the request to the Controller class, and then the specific Action method. Do you have a class called HomeController with the Index method?

Assuming you have a controller that looked like this ...

 public class HomeController : Controller { public ActionResult Index() { return View(); } } 

... then the URL you specified should work. However, ASP.NET MVC expects to find any views related to the Home Controller in a folder named Views \ Home or Views \ Shared under your vdir. In this case, for the action of the index, it is expected that it will find a view named Index.aspx (or .ascx). However, the missing view usually does not lead to 404, which is usually caused by an undetected controller not found by the action method, or in IIS 6 the asp.net pipeline is not in the substitution settings for vdir.

update:

Are you sure your web.config has the HttpHandler MVC in place (so that MVC is in the ASP.NET pipeline). You should have something like this ...

 <add verb="*" path="*.mvc" validate="false" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 

... in the httpHandlers section and this ...

 <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> 

... in the "httpModules" section of the web.config file.

update 2:

Based on your comments, I suspect that you do not have ASP.NET MVC code in the pipeline. You should take your web.config and compare it with one of the newly created MVC site and look for missing configuration items. I suggested a couple above, but maybe more.

+2
source share

All Articles