登录页面无法登录时无法引用其他文件

时间:2011-02-08 01:31:42

标签: c# asp.net css visual-studio-2005

我有一个非常奇怪的问题。 (fyi - 我正在使用表单身份验证并手动创建一个非持久性身份验证凭证/ cookie。)我的登录页面上有应用了图像和CSS。当我在本地运行我的站点(开始没有调试)时,它会显示我的登录页面,但我的图像都没有显示,我的css没有链接。我保证正确引用。

但是,当我在VS的设计视图中查看此页面时,它会显示图像和CSS。此外,如果我运行它并登录,然后单击后退按钮,一切都会显示出来(images / css)!但如果我退出(将我重定向到登录页面),我的images / 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>

1 个答案:

答案 0 :(得分:4)

我认为您的web.config包含

<authorization>
  <deny users="?"/>
</authorization>

这意味着用户无法加载除登录页面之外的任何内容 - 但不能加载其图像,样式表等。您可以将以下内容合并到web.config中以对图像进行例外处理,例如:

<configuration>
  <location path="images">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>
</configuration>