我运行一个使用表单身份验证的ASP.NET网站。事实上,用户不必输入任何内容 - 我用Request.ServerVariables["LOGON_USER"]
并在某个SQL数据库中使用自定义类EmployeeInfo
查找了此用户名,然后根据结果将用户重定向到默认页或显示不同消息的错误页对错误的类型:Windows身份验证自定义验证(来自数据库)
Web.config文件:
<authentication mode="Forms">
<forms loginUrl="Login.aspx"/>
</authentication>
<authorization>
<deny users="?"/>
</authorization>
的Login.aspx:
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
FormsAuthentication.SignOut();
string UserName = Request.ServerVariables["LOGON_USER"];
EmployeeInfo CurrentEmployee = EmployeeInfo.RequestDBInfo(UserName); // SQL magic here
if (CurrentEmployee = null)
Response.Redirect("AccessDenied.aspx?Message=NoInfo");
else
if (CurrentEmployee.Suspended = true)
Response.Redirect("AccessDenied.aspx?Message=Suspended");
if (CurrentEmployee.Expired = true)
Response.Redirect("AccessDenied.aspx?Message=Expired");
if (CurrentEmployee.Position = null)
Response.Redirect("AccessDenied.aspx?Message=NoPosition");
else
FormsAuthentication.RedirectFromLoginPage(CurrentUserName, true);
}
}
这是工作好直到最近,我们不得不切换到Windows身份验证SE好奇的原因。现在,如果用户无效,我的网站默认会打开Login.aspx
页面,并将用户重定向到相应的错误页面。但是用户只需输入URL即可打开任何页面,因为当然不会执行表单身份验证,并且用户可以通过Windows验证身份。
所以我的问题是:
什么是在Windows上实现身份验证的顶部通过数据库附加检查的最佳实践?据我所知,我需要改变Application_AuthenticateRequest
在Global.asax
?