我想知道是否有可能允许用户从子文件夹访问我的js文件。文件夹结构为:
images
js
Models
Views
|-employee
|--css
|---employee.css
|--images
|---img1.jpg
|---img2.png
|--js
|---employee.js
|---employee.html
|--index.html
如果你访问了:
http://localhost/employee/
http://localhost/employee/js/employee.html
没有错误。但是如果你试图访问:
http://localhost/employee/js/employee.js
http://localhost/employee/images/img1.jpg
显示404。
为了授予所需的权限,将auth-exception添加到您的web。配置,允许任何用户访问你的js文件:
<configuration>
<location path="js">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
</configuration>
另外,添加staticFileHandler:
<handlers><add name="JavaScriptHandler" path="*.js" verb="*" preCondition="integratedMode" type="System.Web.StaticFileHandler" /></handlers>
或关于安全的讨论:关于MVC -访问视图文件夹中的css, image, js文件