In ASP.NET MVC, how can I load a script from my view folder?

I edited some of my javascript View in .js files along with the views (not in the Scripts off root folder).

By default, the handler in web.config for views stops loading them:

<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler"/> 

However, I want to override this so that the browser can request .js files from this location.

Does anyone know how I can do this?

Thanks Mark.

0
source share
2 answers

I think I would leave the scripts in the location of the scripts, but if you want to move them, you can do the following:

At the top of the web.config file under the views, find

 <httpHandlers> <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/> </httpHandlers> 

And replace it with the following:

 <httpHandlers> <add path="*.aspx" verb="*" type="System.Web.HttpNotFoundHandler"/> <add path="*.master" verb="*" type="System.Web.HttpNotFoundHandler"/> <add path="*.ascx" verb="*" type="System.Web.HttpNotFoundHandler"/> </httpHandlers> 

You will need to add the extension of each type of file that you want to block.

+2
source

You can change the attribute of the path there to be something less comprehensive than "*" (all), but why are you struggling with the framework conventions? The "Views" folder is intended for organizing (only) view files and is not specifically designed for direct access from the outside. Is there a reason why you cannot put these script files elsewhere in your application?

+1
source

Source: https://habr.com/ru/post/979542/


All Articles