我有一个很奇怪的问题。 (仅供引用 - 我正在使用表单例份验证并手动创建一个非持久性 auth.ticket/cookie。)我的登录页面应用了图像和 CSS。当我在本地运行我的网站时(不调试就开始),它会打开我的登录页面,但我的图像都没有显示,我的 css 也没有链接。我保证引用正确。
但是,当我在 VS 的“设计” View 中查看此页面时,它会显示图像和 CSS。另外,如果我运行它并登录,然后单击后退按钮,一切都会显示出来(图像/css)!但是如果我注销(这会将我重定向到登录页面),我的图像/CSS 不存在!好像页面无法引用自己的资源,除非用户已登录。WTH。我只在我的本地 VS 服务器上遇到这个问题;当我把它放在实时服务器上时,它似乎工作正常 (woot)。有人知道为什么会这样吗?
这是我的登录页面的一部分,它请求图像/css:
...
<head runat="server">
<link rel="stylesheet" type="text/css" href="styles/BodyLayout.css" />
<title>Optoma USA - Login</title>
</head>
<body>
<center>
<div style="text-align:left; width:990px; height:780px; background-color:White;">
<div id="divBody">
<form id="form1" runat="server" target="_self">
<center>
<div style="height:100px; width:600px; text-align:center;">
<img src="images/Optoma_Logo.gif" alt="Unable to display image." />
</div>
</center>
...
此外,这是我在 web.config 中的授权代码:
<authentication mode="Forms">
<forms loginUrl="~/index.aspx" name="adAuthCookie" path="/">
</forms>
</authentication>
<!--<authorization>:-->
<authorization>
<!-- <deny>: will deny all users and redirect to login page,
unless they are properly authenticated-->
<deny users="?"/>
<!--<allow>: might be configured later. probably will not need-->
<allow users="*"/>
</authorization>
最佳答案
我认为你的 web.config 包含
<authorization>
<deny users="?"/>
</authorization>
这意味着用户不能加载除登录页面以外的任何内容——但不能加载它的图像、样式表等。您可以将以下内容合并到 web.config 中以对图像进行异常(exception)处理,例如:
<configuration>
<location path="images">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
</location>
</configuration>
关于c# - 登录页面不能在未登录的情况下引用其他文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4928716/