0

I have some javascript files that are named starting with an underscore. When I publish these it seems they can't be found. Is there some rule that stops these being viewed by the browser when running on IIS? I think I remember something like that for the cshtml files but didn't know that applies to js files.

4
  • Are they actually published and exists on the server? Commented Nov 9, 2011 at 5:51
  • Can't say right now as I am having problems getting a remote connection to the server. However other files publish okay. These js are used within MVC areas. I am wondering if that is the problem. Commented Nov 9, 2011 at 6:11
  • Yes the javascript files are on the server. When I am on the server and click on that javascript within IIS it opens the browser and says cannot be found. Click on js outside of the area and no problem it opens up. Commented Nov 9, 2011 at 8:25
  • “These js are used within MVC areas” — Are they stored in Views folder? Commented Nov 9, 2011 at 8:49

2 Answers 2

1

I found the following post, which talks about files with "_" prefix: Why does Razor _layout.cshtml have a leading underscore in file name?.

By convention, the Razor pages that cannot be shown by the browser via direct request are prefixed with "_". Following is one of the comments from the post:

Razor was developed for ASP.NET Web Pages (WebMatrix), which doesn't have the same sort of protection built in regarding Views folders and Routing that you get within MVC. Since layout pages in Web Pages are not intended to be served directly, they are prefixed with the underscore. And the Web Pages framework has been configured not to allow files with leading underscores in their names from being requested directly.

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

1 Comment

+1 Looks like js files are stored inside ~/Views folder. Putting them to ~/Scripts or ~/Content folder should help.
0

In your View is the reference to them pointed to the correct path?

<script src="@Url.Content("~/Scripts/jquery-custom.js")" type="text/javascript"></script>

I would also hit Control + F5 several times after the page loads to make sure it is not cached and that is the reason it is not pulling down.

Comments

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.