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.

Tobee
  • 11
  • 5
  • why do you access: http://localhost/employee/js/employee.js and not http://localhost/Views/employee/js/employee.js (according your notation from above) – flo scheiwiller Sep 15 '15 at 16:02

1 Answers1

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

Community
  • 1
  • 1
flo scheiwiller
  • 2,706
  • 2
  • 17
  • 15
  • Sorry my bad, I updated my question. I tried your suggestion still no luck. @flo – Tobee Sep 15 '15 at 14:13
  • i updated my answer. See also: http://stackoverflow.com/questions/604883/where-to-put-view-specific-javascript-files-in-an-asp-net-mvc-application – flo scheiwiller Sep 15 '15 at 14:43
  • 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 – Tobee Sep 15 '15 at 14:58
  • 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 – flo scheiwiller Sep 15 '15 at 15:14
  • I tried the suggestion of davesw from here http://stackoverflow.com/questions/604883/where-to-put-view-specific-javascript-files-in-an-asp-net-mvc-application still no luck. – Tobee Sep 15 '15 at 15:28