简体   繁体   中英

How to have static resource requests passed to MVC (IIS 7.5)

I have an ASP.NET MVC application running on IIS 7.5. Somehow, on my machine, requests ending in '.js' are not caught by the corresponding controller action while they are on a colleague's machine.

The action has the ActionName attribute specified:

ActionName("Scripts.js")
public ActionResult ScriptsJS()
{
    ...
}

When I issue a request to 'Scripts.js', I get a 404 while for my colleague's machine, he gets the result of the ScriptsJS action.

I figure it's something I have to configure in IIS, since the same code runs fine on my colleague's machine (also running IIS 7.5).

So, how do I configure IIS to pass requests ending in '.js' to the MVC handler?

ASP.NET does not process every request sent the web server, for example is does not need to handle html, jpg, css files as they exist on disk and can be sent straight to the user. If you want to configure IIS to pass any of these files to ASP.NET then you will need to configure a Handler Mapping for your site.

For how to do this look at this question How to add wildcard mapping

It turned out that installing "IIS Recommended Configuration" using the Web Platform Installer resolved this issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM