小编Dav*_*per的帖子

如何修复:您没有查看此目录或页面的权限?

我在 .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 - 未经授权

HTTP 错误 401.0 - 未经授权 - 图片位于此处

这是我的网络配置的一部分

<system.webServer>
      <handlers> …
Run Code Online (Sandbox Code Playgroud)

c# xml asp.net asp.net-mvc visual-studio

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

asp.net ×1

asp.net-mvc ×1

c# ×1

visual-studio ×1

xml ×1