i want to specify a path to a file relative to the root of the web-site. e.g.
<script type="text/javascript" src="/Scripts/jquery-1.7.2.min.js"></script>
In ASP.net that causes problems because the "root" of the site can be different from the root of server.
e.g. Specifying src
results in a GET
from path
src="/Scripts/jquery-1.7.2.min.js"
http://localhost:64276/Scripts/jquery-1.7.2.min.js 404
src="~/Scripts/jquery-1.7.2.min.js"
http://localhost:64276/WebSite/Adminstration/~/Scripts/jquery-1.7.2.min.js 404
src="~Scripts/jquery-1.7.2.min.js"
http://localhost:64276/WebSite/Adminstration/~Scripts/jquery-1.7.2.min.js 404
src="~/Scripts/jquery-1.7.2.min.js" runat="server"
500 Unexpected character '$'
How can i specify a site relative path when using HTML in ASP.net?
If you're using ASP.net MVC, then src="~/scripts/blahblah"
should work fine.
If you're not using MVC, then you'll need to use something like:
<script src='<%= this.ResolveClientUrl("~/Scripts/jquery-1.7.2.min.js") %>' type="text/javascript"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With