[英]css and js files not found(server responded with a status of 404) while browsing application on iis7
我在vs 2010上发布了我的解决方案。对样式表和js文件的引用示例( 第一种方法 ):
<link href="../../Content/CSS/Login.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/ApplicationSecurity/AuthenticateUser.js" type="text/javascript"></script>
这些在调试时工作正常。 但是在iis 7上浏览时,资源无法加载。 在其他应用程序中,我使用了( 第二种方法 ):
<link href="~/Content/CSS/Login.css" rel="stylesheet" type="text/css" />
这在iis上的调试和浏览期间都可以正常工作。 视图页面的URL为:
http://localhost/LaunchLogin/
控制台错误:
Failed to load http://localhost/Content/css/Login.css resource: the server responded with a status of 404 (Not Found)
它应该在以下位置搜索文件:
http://localhost/LaunchLogin/Content/css/Login.css
谁能解释iis如何尝试访问资源? 另外,如何配置iis或以第一种方法可用于iss浏览的方式发布?
使用~
基本路径没有问题,并且是最好的(而且正如您所说;可以正常工作),但是如果您仍然需要相对路径,请尝试使用这些标记,我将删除一个目录向上路径。
<link href="../Content/CSS/Login.css" rel="stylesheet" type="text/css" />
<script src="../Scripts/ApplicationSecurity/AuthenticateUser.js" type="text/javascript"></script>
顺便说一句,
如果您的URL是http://localhost/LaunchLogin/
而CSS文件位于http://localhost/LaunchLogin/Content/css/Login.css
则用于链接CSS的代码应为:
<link href="Content/CSS/Login.css" rel="stylesheet" type="text/css" />
<script src="Scripts/ApplicationSecurity/AuthenticateUser.js" type="text/javascript"></script>
如果您愿意,那么下一个最佳方法是在CSS和JS链接中使用绝对路径 。 您可以使用以下技巧来做到这一点:
public String absRoot='http://localhost/LaunchLogin/';
并将其设置为您网站的根目录。 <link href="<%=StaticClassName.absRoot %>Content/CSS/Login.css" rel="stylesheet" type="text/css" />
<script src="<%=StaticClassName.absRoot %>Scripts/ApplicationSecurity/AuthenticateUser.js" type="text/javascript"></script>
absRoot
值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.