I have a question about relative path to external javascript, css and images files in Asp.C# application.
I have pages with 2 - 5 sub levels so my javascript and css files looks like
../../../../../javascriptfile.js
../../../cssfile.css
../../../../../../image.jpg
In case if it will be additional sub level application won't find files.
What is the best practices to specify path to file???
I have a question about relative path to external javascript, css and images files in Asp.C# application.
I have pages with 2 - 5 sub levels so my javascript and css files looks like
../../../../../javascriptfile.js
../../../cssfile.css
../../../../../../image.jpg
In case if it will be additional sub level application won't find files.
What is the best practices to specify path to file???
Share Improve this question asked Mar 6, 2011 at 17:08 Anthony FernandesAnthony Fernandes 111 silver badge2 bronze badges 1- the answer will be just to reorganize the files to reduce the usage of such relative path :) – Ant's Commented Mar 6, 2011 at 17:13
3 Answers
Reset to default 6Keep in mind when considering these answers that "root-relative" and "root of the site" may really mean the root of the path following the domain name in the url. You may need to take into account scenarios where your web site is not located at the root. In such scenarios, root-relative paths would potentially point to a different web site.
In ASP.NET you can use a leading ~ to generate urls relative to the root of current site for most server-side controls, as in:
<img src="~/image.jpg" runat="server">
You can also use the ResolveUrl method (and other similar methods) to expand such paths without using server-side controls.
Use a root-relative path like this:
/js/javascriptfile.js
/css/style.css
the first / means at the root of the site.
Use absolute or root-relative paths to avoid confusion in multi-level pages.
Look here for more information: http://www.motive.co.nz/glossary/linking.php
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744148812a4560551.html
评论列表(0条)