0

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.

1
  • why not use the scripts folder, as the convention goes? the javascript isn't a view, after all. Commented Oct 14, 2009 at 13:35

2 Answers 2

2

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.

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

1 Comment

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

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?

2 Comments

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.
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.

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.