admin管理员组文章数量:1355600
I build a simple ASP MVC4 application which uses ExtJS.
My main view has link to my main employee.js file:
<script src="app/employee.js" type="text/javascript"></script>
I'm publishing my application to server in my local network.
On my development machine when I access url http:\\local-iis\holidays
application is loaded correctly and displayed.
But on 3 others puters in the same network I get error, because browser can't find that js file.
My project structure looks like so:
--holidays (project name) +--app +--myapp.js +--Controllers +--Models +--(rest of ASP folders)
On my development machine when I access http:\\local-iis\holidays
on chrome and I inspect source I see line:
<script src="app/employee.js" type="text/javascript"></script>
after I rollover that entry
I see correct path:
http:\\local-iis\holidays\app\employee.js (I translated urlopy to holidays)
on other puters for the same page source directory name is removed (holidays
)
I tried clearing cache, installing other browsers, switching to other puters but everything failed-on some puters this is working and on some it isn't.
I'm not asking for specific solution, but something to get started with.
It's my first project in MVC 4 and I don't know how should I configure my application to get those urls working.
I don't know why my application is removing that directory name (it is referring to root of my local-iis server)
I asked on ExtJS forum and they said this is probably IIS or ASP setting issue.
I build a simple ASP MVC4 application which uses ExtJS.
My main view has link to my main employee.js file:
<script src="app/employee.js" type="text/javascript"></script>
I'm publishing my application to server in my local network.
On my development machine when I access url http:\\local-iis\holidays
application is loaded correctly and displayed.
But on 3 others puters in the same network I get error, because browser can't find that js file.
My project structure looks like so:
--holidays (project name) +--app +--myapp.js +--Controllers +--Models +--(rest of ASP folders)
On my development machine when I access http:\\local-iis\holidays
on chrome and I inspect source I see line:
<script src="app/employee.js" type="text/javascript"></script>
after I rollover that entry
I see correct path:
http:\\local-iis\holidays\app\employee.js (I translated urlopy to holidays)
on other puters for the same page source directory name is removed (holidays
)
I tried clearing cache, installing other browsers, switching to other puters but everything failed-on some puters this is working and on some it isn't.
I'm not asking for specific solution, but something to get started with.
It's my first project in MVC 4 and I don't know how should I configure my application to get those urls working.
I don't know why my application is removing that directory name (it is referring to root of my local-iis server)
I asked on ExtJS forum and they said this is probably IIS or ASP setting issue.
Share Improve this question edited Mar 29, 2013 at 16:27 Misiu asked Mar 29, 2013 at 15:18 MisiuMisiu 4,92922 gold badges100 silver badges209 bronze badges 6-
The backslash is throwing me off. Do you really have this or did you mean
/
– Mike Christensen Commented Mar 29, 2013 at 15:20 - @MikeChristensen which backslash do You mean? – Misiu Commented Mar 29, 2013 at 15:43
-
All of them. For example,
http:\\local-iis\holidays\app\employee.js
– Mike Christensen Commented Mar 29, 2013 at 15:45 - @MikeChristensen I added screenshot to show what I mean with those backslashes. – Misiu Commented Mar 29, 2013 at 16:03
- I don't see any backslashes in your screenshot. – Mike Christensen Commented Mar 29, 2013 at 16:07
1 Answer
Reset to default 8Never hardcode urls in an ASP.NET MVC application:
<script src="app/myapp.js" type="text/javascript"></script>
Just use helpers:
<script src="~/app/myapp.js" type="text/javascript"></script>
The ~/app/myapp.js
will properly go through the Url.Content
helper which in turn will generate the correct url no matter where your application is hosted. For example if your application is hosted locally in IIS Express it might look like this:
<script src="/app/myapp.js" type="text/javascript"></script>
and when deployed in a virtual directory in IIS it might look like this:
<script src="/holidays/app/myapp.js" type="text/javascript"></script>
The helper will take care of it.
In Razor v1.0 (ASP.NET MVC 3) you would have to explicitly use the helper:
<script src="@Url.Content("~/app/myapp.js")" type="text/javascript"></script>
本文标签: aspnet mvcjavascript file in subdirectory not loadingStack Overflow
版权声明:本文标题:asp.net mvc - javascript file in subdirectory not loading - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743976676a2570907.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论