views:

158

answers:

2

I've refactored some of my View's javascript out into .js files alongside the views (not in the Scripts folder off root).

By default, the handler in web.config for the views stops these being loaded:

<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler"/>

However, I want to override this to allow the browser to request .js files from this location.

Does anyone know how I can do this?

Thanks, Mark.

A: 

I think I would leave the scripts in the scripts location but if you wanted to move them you could do the following:

At the top of the web.config file under views look for

<httpHandlers>
  <add path="*" verb="*"
      type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>

And replace it with the following:

<httpHandlers>
  <add path="*.aspx" verb="*"
      type="System.Web.HttpNotFoundHandler"/>
    <add path="*.master" verb="*"
        type="System.Web.HttpNotFoundHandler"/>
    <add path="*.ascx" verb="*"
        type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>

You will need to add the extension of each file type you want to keep blocked.

Michael Gattuso
Thanks. Yes, I was hoping to avoid this scenario... Shame there is no 'exclude="*.js"' convention to come to my aid.
Mark
+1  A: 

You could change the path attribute there to be something less comprehensive than "*" (everything), but why are you fighting the conventions of the framework? The Views folder is intended to organize (only) the view files, and is specifically not meant to be accessed directly from the outside. Is there some reason why you can't put those script files elsewhere in your app?

Sixten Otto
Thanks, however, the client-side script for my view _is_ part of my view, just because I want to refactor it out into separate files shouldn't mean it needs to live elsewhere IMO. Nothing wrong with wrestling a few pesky conventions now and then.
Mark
Hey, sure, it's your project. Just seems like the same argument could be made for every other web asset in there: other scripts, images, CSS, .... You're going to be fighting the framework all the way. But you *can* do it.
Sixten Otto