问题
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?
回答1:
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.
回答2:
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!
回答3:
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 = "" }
);
回答4:
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
回答5:
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.
回答6:
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
回答7:
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
来源:https://stackoverflow.com/questions/1840939/asp-net-mvc-httpexception-strange-file-not-found