c# - Best practices, How to specify relative path for css,javascript and images files? - Stack Overflow

I have a question about relative path to external javascript, css and images files in Asp.C# applicatio

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
Add a ment  | 

3 Answers 3

Reset to default 6

Keep 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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信