网站部署后相对路径不起作用 [英] Relative path not working when website is deployed

查看:283
本文介绍了网站部署后相对路径不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,该网站的样式表类似于"/stylesheets/main.css".现在,当我在Visual Studio中运行站点时,此方法可以正常工作.但是,当我将站点部署到Windows Server 2003时,该路径停止工作.如果我返回代码并将路径从"/stylesheets/main.css"更改为"stylesheets/main.css",则该站点在服务器上可以正常工作.我在不同的服务器上有另一个网站,该网站使用相同的路径样式("/stylesheets/main.css")和样式表,并且工作正常.我真的不想更改所有路径,甚至不确定这是否是代码或服务器问题.任何帮助或想法都会很棒.谢谢.

I have a website that has a relative path to a stylesheet that looks like this "/stylesheets/main.css". Now this works fine when I run the site in Visual Studio. But when I deploy the site to our Windows Server 2003 the path stops working. If I go back into code and change the path from "/stylesheets/main.css" to "stylesheets/main.css", the site works fine on the server. I have another website on a different server that uses the same path style ("/stylesheets/main.css") and stylesheet and works with no problems. I really don't want to change all the paths, and am not even sure if this is a problem with the code or the server. Any help or ideas would be great. Thanks.

推荐答案

站点是否已部署到域的根目录?如果网站位于

Is the site deployed to the domain's root? If the site is at

http://example.com/somefolder/

然后将路径/stylesheet/main.css解释为

http://example.com/stylesheet/main.css

而不是

http://example.com/somefolder/stylesheet/main.css

如@Kit所示,您可以通过解析应用程序文件夹的路径来解决此问题.我经常在ASP.NET中这样做,如下所示:

As @Kit indicated, you can work around this by resolving the path to your application's folder. I have often done this in ASP.NET as follows:

<link rel="stylesheet" type="text/xss" href="<%= ResolveUrl("~/stylesheet/main.css") %>"/>

如果这不是问题,那么您将不得不提供更多细节.

If that's not the problem, you're going to have to give a bit more detail.

这篇关于网站部署后相对路径不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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