我在 .NET MVC 应用程序中有一个新的遗留代码。
第一次运行它时,提示 Windows 身份验证警报让我登录。我已经在 web.config 中禁用了它。
然后很明显看到验证码,但我已经评论它跳转了。
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
//if (!Request.IsAuthenticated) return;
//var userPrincipal = new CompanyPrincipal((WindowsIdentity) HttpContext.Current.User.Identity);
//var userPrincipal = new CompanyPrincipal(WindowsIdentity.GetCurrent());
//if (userPrincipal.IsAuthenticated)
//{
//HttpContext.Current.User = userPrincipal;
WindowsPrincipal fakeUser = new WindowsPrincipal(WindowsIdentity.GetCurrent());
HttpContext.Current.User = fakeUser;
//}
//else
//{
// Response.StatusCode = 401;
// Response.StatusDescription = "Unauthorized";
// Response.SuppressContent = true;
// HttpContext.Current.ApplicationInstance.CompleteRequest();
//}
}
Run Code Online (Sandbox Code Playgroud)
在此之后,我的应用程序显示错误消息HTTP 错误 401.0 - 未经授权
这是我的网络配置的一部分
<system.webServer>
<handlers> …Run Code Online (Sandbox Code Playgroud)