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?
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...
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
totrue
, and see if that stops the errors appearing.I may have been wrong with my initial answer to this. I think the problem lies in the fact that I did not have a favicon for my site, and that this request (on each browser refresh) was being processed by the MVC runtime.
Adding a favicon and an ignore route (as in the question linked below, seems to sort this out properly.
Serving favicon.ico in ASP.NET MVC
I'm leaving this link on as well, as there was some useful items that I worked through here too:
ASP.NET MVC on IIS6
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.
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
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