0

我的网站有 Windows 身份验证,并且只允许我在 web.config 文件中提到的那些用户。其余用户应该无法访问该网站,所以我有一个 denied.html 页面,我希望其他用户在尝试访问时获得access.Following 是我的代码。

在 web.config

<authentication mode="Windows">
</authentication>    
<authorization>
  <allow users="domain\user1, domain\user2" />
  <deny users="*"/>
</authorization>

在 Global.asax 的 Application_EndRequest 方法中

 protected void Application_EndRequest(Object sender, EventArgs e)
{
    HttpContext context = HttpContext.Current;
    if (context.Response.Status.Substring(0, 3).Equals("401"))
    {
        context.Response.ClearContent();
        Server.Execute("~/Denied.html");
    }
}

在 Denied.html 中

<img src="Images/Access_Denied.jpg" />

现在我有 2 个问题,我已经尝试过并用谷歌搜索但找不到解决方案。

1) 无权访问的用户会收到一个对话框,要求他们输入 LAN 凭据,只有在 3 次尝试后,他们才会被重定向到 denied.html。有没有办法避免登录提示直接获取denied.html?

2) 我试图在 denied.html 中加载的图像显示在页面设计中,但没有出现在运行时,我就是不知道为什么?

提前致谢!

4

1 回答 1

0

我无法回答 #1,但 #2 发生是因为您拒绝访问配置文件的资源。您可以在 web.config 中覆盖它...

...
...
</system.web>
  <location path="Images">
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
  </location>
于 2013-03-01T14:53:06.370 回答