Tobee
Tobee

Reputation: 11

How can I allow users to access js files from sub-sub folders ASP .NET MVC3

I'm wondering if its possible to allow users to access my js files from sub-sub folders. The folder structure is:

images
js
Models
Views
|-employee
|--css
|---employee.css
|--images
|---img1.jpg
|---img2.png
|--js
|---employee.js
|---employee.html
|--index.html

If you access any of:

http://localhost/employee/
http://localhost/employee/js/employee.html

there's no error. But if you try to access any of:

http://localhost/employee/js/employee.js
http://localhost/employee/images/img1.jpg

it gives me 404.

Thanks in advance.

Upvotes: 1

Views: 983

Answers (1)

flo scheiwiller
flo scheiwiller

Reputation: 2706

In order to grant the required permissions add the auth-exception to your web.config, to allow any user the access to your js files:

 <configuration>
   <location path="js">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>
  </location>
 </configuration>

In Addition, add the staticFileHandler:

  <handlers><add name="JavaScriptHandler" path="*.js" verb="*" preCondition="integratedMode" type="System.Web.StaticFileHandler" /></handlers>

or discussion about safety: on MVC - Accessing css, image, js files in view folder

Upvotes: 1

Related Questions