1

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.

1

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

5 Comments

Sorry my bad, I updated my question. I tried your suggestion still no luck. @flo
i updated my answer. See also: stackoverflow.com/questions/604883/…
I tried the suggestions from the links still no luck. Correct me if I'm wrong the web.config file you're/they referring is Views\Web.config right? @flo
web.config files are organized by hierarchy. meaning that a restriction of a web.config in a subfolder can add, but not undo restrictions of any web.config in a parent folder
I tried the suggestion of davesw from here stackoverflow.com/questions/604883/… still no luck.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.