在我的 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/