最佳实践,如何指定CSS,javascript和图像文件的相对路径? [英] Best practices, How to specify relative path for css,javascript and images files?

查看:143
本文介绍了最佳实践,如何指定CSS,javascript和图像文件的相对路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于在Asp.C#应用程序相对路径外部JavaScript,CSS和图像文件的问题。

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

我有2页 - 5分的水平,所以我的JavaScript和CSS文件看起来像

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???

推荐答案

在考虑这些问题的答案时,请记住,根目录相对和站点根的真正意思可能路径的根下的域名该URL。你可能需要考虑在您的网站不位于root帐户的情况。在这样的情况下,根目录相对路径将可能指向不同的网站。

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.

在ASP.NET你可以使用导致〜产生相对于当前站点的根目录对于大多数服务器端控件的URL,如下所示:
< IMG SRC =〜/ image.jpg的=服务器>

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">

您也可以使用 RESOLVEURL 方法(以及其他类似的方法)来展开这样的路径,而无需使用服务器端控件。

You can also use the ResolveUrl method (and other similar methods) to expand such paths without using server-side controls.

这篇关于最佳实践,如何指定CSS,javascript和图像文件的相对路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆