简体   繁体   English

记录失败的IIS登录(Windows身份验证)

[英]Log failed IIS login (windows authentication)

In our application, we offer the use of Windows authentication. 在我们的应用程序中,我们提供Windows身份验证的使用。 For this, the browser pops-up a window. 为此,浏览器会弹出一个窗口。 When a user is logged in correctly, I can log this in the code after this: 当用户正确登录后,我可以在下面的代码中登录:

 if (HttpContext.Current.User.Identity.IsAuthenticated) c.Response.Redirect(General.PathPrefix() + "Default.aspx");

My question is, how can I log a user not getting authenticated, all code seems to stop when the login fails, and I get a 401 response. 我的问题是,如何记录未通过身份验证的用户,登录失败后所有代码似乎都停止,并且得到401响应。

You can log this error in the Global.asax file using the code below 您可以使用以下代码在Global.asax文件中记录此错误

public class CoolMvcApplication : System.Web.HttpApplication
{
    protected void Application_Error(object sender, EventArgs e)
    {
        Exception exception = Server.GetLastError();
        //check here if this exception is an unauthorized access error, if so
        Server.ClearError();
        Response.Redirect("/not_loggedin");
    }
}

Also you can achieve this by using filters and assert there if the error is unauthorized access and follow the same logic. 您也可以通过使用过滤器来实现此目的,并在错误未经授权的情况下声明错误并遵循相同的逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM