asp.net mvc 3 and static resources 404'ing when using "Local IIS Web server"
Here's the situation:
- ASP.NET MVC 3 application using Razor as the view engine.
- Works fine under Visual Studio Development Server (Cassini)
- However, when I switch over to "Use Local IIS Web server", the site functions, but every static resource 404s (again, there were no issues under Cassini).
- ASP.NET 4.0, Windows 7 Ultimate x64, IIS 7.5, Integrated Pipeline, Network Service as app pool identity.
Specifically, an exception for trying to access a static file that is known to exist (i.e. remove application files, specifically DLLs with route information, etc. and it is served up without issue). Again, this occurs for all static files including i.e. /public/scripts/jquery.js:
Error in Path :/favicon.ico Raw Url :/favicon.ico Message :Path '/favicon.ico' was not found. Source :System.Web Stack Trace : at System.Web.HttpNotFoundHandler.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) TargetSite :Void ProcessRequest(System.Web.HttpContext) NLogLogger.Fatal => NLogLogger.Fatal => LoggerImpl.Write
I'm baffled. I've verified that a test default ASP.NET MVC 3 app runs fine under both VS Development Server and Local IIS Web server on this machine.
My hope is that someone else has run into a similar issue. In case it helps, here are my routes:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("favicon.ico");
routes.MapRoute(
"Login", // Route name
"login", // URL with parameters
new { controller = "Session", action = "Create" } // Parameter defaults
);
routes.MapRoute(
"Logout", // Route name
"logout", // URL with parameters
开发者_高级运维 new { controller = "Session", action = "Delete" } // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
Of course, it turns out to be something extremely simple: there was an HttpHandler defined in the root Web.config instead of just the View directory's Web.config
<handlers>
<remove name="BlockViewHandler" />
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
Obvious now, but hopefully by posting here it might save somebody else wasting time on something so obvious. See http://haacked.com/archive/2008/06/25/aspnetmvc-block-view-access.aspx for more info.
精彩评论