MVC Route to Action for Javascript file

后端 未结 1 537
我在风中等你
我在风中等你 2020-12-21 16:53

I am trying to add a mvc route to generate a javascript from the controller. I have added the following route and it doesn\'t work:

routes.MapRouteWithName(
         


        
1条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-21 17:41

    how do I make this work?

    IIS intercepts the request because it contains a file extension and hijacks it thinking it is a static file and not passing it to your application.

    To make it work you should tell IIS not to do that. Inside the section you could add the following handler to indicate that requests with the specified pattern should be handled by the managed pipeline:

    
        
            ...
            
        
    
    

    Some people might also tell you to use:

    
    

    but I wouldn't recommend you doing that because this means that all requests to static resources will now be flowing through the managed pipeline which could have a negative performance overhead for your application. The handler syntax allows you to selectively enable this only for certain route patterns and HTTP verbs.

    0 讨论(0)
提交回复
热议问题