Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify path relative to site root?

Tags:

asp.net

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?

See also

  • How to set the Site-Root Relative Path (for localhost) on IIS on my web application
  • ASP.NET relative path
  • Relative path from site root
  • JQuery: Visual studio, error CS1056: Unexpected character '$'
like image 973
Ian Boyd Avatar asked Nov 21 '12 21:11

Ian Boyd


1 Answers

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>
like image 112
Michael Dunlap Avatar answered Sep 30 '22 05:09

Michael Dunlap