I have my js files inside areas and I cannot access them. When I move them outside the MVC areas then I can access.
I have tried the following:
This works:
<script src="@Url.Content("~/Scripts/jquery/_Roles.js")" type="text/javascript"></script>
This does not work:
<script src="@Url.Content("~/Areas/Administration/Scripts/Roles/_Roles.js")" type="text/javascript"></script>
Could there be something different about files under the Areas folder that blocks scripts?
Found an answer in another Stack Overflow question and tweaked it for areas.
Modify /Areas/AreaName/Views/web.config file to enable the webserver to serve JS and CSS files:
<system.web>
<httpHandlers>
<add path="*.js" verb="GET,HEAD" type="System.Web.StaticFileHandler" />
<add path="*.css" verb="GET,HEAD" type="System.Web.StaticFileHandler" />
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<!-- other content here -->
</system.web>
<system.webServer>
<handlers>
<remove name="BlockViewHandler"/>
<add name="JavaScript" path="*.js" verb="GET,HEAD" type="System.Web.StaticFileHandler" />
<add name="CSS" path="*.css" verb="GET,HEAD" type="System.Web.StaticFileHandler" />
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
<!-- other content here -->
</system.webServer>
This will allow serving of .js and .css files, and will forbid serving of anything else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With