避免登录Windows身份验证网站的提示

时间:2013-02-28 17:57:01

标签: asp.net image windows-authentication

我的网站有Windows身份验证,只允许我在web.config文件中提到的thoese用户。其他用户应该无法访问该网站,因此我有一个我希望其他用户获取的denied.html页面他们试图访问。以下是我的代码。

在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中加载的图片显示在页面的设计中但是没有在运行时出现,我只是想不通为什么?

提前致谢!

1 个答案:

答案 0 :(得分:0)

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

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