gpt4 book ai didi

c# - 不显示 css 或图像

转载 作者:行者123 更新时间:2023-11-28 02:52:47 25 4
gpt4 key购买 nike

在我的 web.config 中,我正在尝试处理服务器错误,我已将这段代码放在 <system.webServer> 中:

<httpErrors errorMode="Custom" defaultResponseMode="File">
<remove statusCode="404"/>
<error statusCode="404" path="FileNotFoundError.html" />
<remove statusCode="403"/>
<error statusCode="403" path="NoAccessErrorPage.html" />
</httpErrors>

当我尝试访问 http://localhost:12112/asdd 时其中 asdd 指的是任何目录或文件。我得到了具有适当样式和图像的所需页面。然而,当我点击 http://localhost:12810/asdd/asdd一个不存在的目录中的额外目录,我不再获得我的 css 或图像。

这是我的图像定义src="Images/Image1.png"我在头部的 CSS 定义:<link rel="stylesheet" type="text/css" href="style.css" />

注意:如果我使用内联样式,我可以获得我的 css,但我没有办法处理图像,如果可能的话,我想使用外部样式表。

最佳答案

您应该使用 ~ 运算符 ( msdn ):

src="~/Images/Image1.png"

ASP.NET includes the Web application root operator (~), which you can use when specifying a path in server controls. ASP.NET resolves the ~ operator to the root of the current application. You can use the ~ operator in conjunction with folders to specify a path that is based on the current root.

关于c# - <httpErrors> 不显示 css 或图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46591325/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com