views:

680

answers:

7

I'm running asp.net MVC site on IIS6 - I've edited my routing to look like the following:

  routes.MapRoute(
            "Default",                              
            "{controller}.aspx/{action}/{id}",   
            new { controller = "Home", action = "Index", id = "" }  
        );

        routes.MapRoute(
         "Root",
         "",
         new { controller = "Home", action = "Index", id = "" }
       );

So all my urls now contain .aspx (as per one of the solutions from Phil Haack). Now, I catch all unhandled exceptions using Elmah, and for almost every page request, I get the following error caught by Elmah, that I never see on the front end (everything works perfectly):

System.Web.HttpException: The file '/VirtualDirectoryName/Home.aspx' does not exist.

System.Web.HttpException: The file '/VirtualDirectoryName/Home.aspx' does not exist.
   at System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath)
   at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
   at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
   at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
   at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
   at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
   at System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
   at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig)
   at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

There is a Home controller, and it should be found, but I'm not sure a) where this is being called from, and b) why I don't see this error on the front end. Any ideas?

Edited with answer:

I think the answer for this can be found in this question:

http://stackoverflow.com/questions/34194/asp-net-mvc-on-iis6

A: 

I think it is because you have the .aspx extension in your route. It should map to the controller, but the .aspx file is actually the view. What happens if you run it like...

routes.MapRoute(
            "Default",                              
            "{controller}/{action}/{id}",   
            new { controller = "Home", action = "Index", id = "" }  
        );

        routes.MapRoute(
         "Root",
         "",
         new { controller = "Home", action = "Index", id = "" }
       );
Dan Hedges
Having the .aspx extension is there, as it is required. This allows me to run natively on IIS6, which doesn't support the above method out of the box.
Paddy
A: 

I'm not too sure, but when I set up my global.asax for running on IIS 6,

using the .mvc extension, the route did not contain the controller:

routes.MapRoute( "Default",
"{controller}.mvc/{action}/{id}",
new { action = "Index", id = "" }
);

it may work if you change the '.mvc' to '.aspx'
i'm not too sure if that's how the .aspx way is supposed to be set up tho. this may work. give it a shot

Matt
Thanks, I'll look into that one.
Paddy
Unfortunately, that does not seem to do the trick.
Paddy
+1  A: 

Go to IIS6 application Properties > configuration and check that the "verify file exists" is unchecked for the .aspx extension. If it is checked it will not work correctly.

Michael Gattuso
This is indeed unchecked.
Paddy
+1  A: 

If you open IIS and right click on your website in the IIS Manager Console (inetmgr.exe), you should be able to select properties and get a tabbed dialog. On this , select "Home Directory" then configuration.

In the configuration dialog you should get a list of ISAPI applications. In there is there one for the extension .* ?

If there is not then you need to add it and point it at the aspnet_isapi.dll (have a look at the handler for .aspx files). Then IIS will know that any incoming url without an extension (for exmaple an asp.net mvc url of http://localhost/myappp/myPage/ ) will still run the asp.net extensions, then I think you should be able to run it without the .aspx bit (you need to uncheck the "check file exists" checkbox when you create the filter).

Hope that helps!

Dan Hedges
I was hoping not to add a wildcard mapping like this - the solution I'm attempting was on Steve Sanderson's blog.
Paddy
A: 

It looks like what's happening is that your site is looking for the standard ASP.NET page before the MVC routing engine gets a look in, throwing the exception that's being caught by ELMAH, and then the routing engine kicks in, and finds the correct controller - I believe this is the standard behaviour.

You could try setting RouteExistingFiles to true, and see if that stops the errors appearing.

Zhaph - Ben Duguid
A: 

Check the ignore route section of your code as well, once I have wrongly configured the ignore route part and that produced a strange files does not exist error.. check that and see

Nirosh
A: 

I think the answer for this can be found in this question:

http://stackoverflow.com/questions/34194/asp-net-mvc-on-iis6

Paddy