【问题标题】:HOW TO FIX: You do not have permission to view this directory or page?如何修复:您无权查看此目录或页面?
【发布时间】:2016-12-20 00:29:15
【问题描述】:

我在 .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();
        //}
    }

在此之后,我的应用会显示错误消息 HTTP Error 401.0 - Unauthorized

HTTP Error 401.0 - Unauthorized - image here

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

<system.webServer>
      <handlers>
        <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
        <remove name="OPTIONSVerbHandler" />
        <remove name="TRACEVerbHandler" />
        <remove name="UrlRoutingModule-4.0" />
        <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
      </handlers>
  </system.webServer>

还有这部分

<system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <globalization culture="es-MX" uiCulture="es-MX" />
    <!--<authentication mode="Windows" />-->    
    <authentication mode="None"/>    
    <authorization>
         <allow users="*" />
         <!--<deny users="*" />-->
      </authorization>
  </system.web>

我错过了什么?我已经授予应用程序文件夹权限,但我认为还有更多内容。

有什么建议吗??我在 web.config 中有一些绑定和端点。

问候!!

【问题讨论】:

  • 此 IIS 站点是否配置为 ASP.NET 应用程序?如果不是,这可能只是 IIS 错误,而不是 ASP.NET。
  • 我在 IIS Express 中运行应用程序,没有部署。但我对 IIS 配置没有足够的了解。我回答你的问题了吗??

标签: c# asp.net xml asp.net-mvc visual-studio


【解决方案1】:

由于您使用的是 Windows 主体,也许您应该将身份验证模式更改为“Windows”。

【讨论】:

  • 但是如果我想跳认证怎么办,我该怎么办??
【解决方案2】:

就我而言,App_Start =&gt; FilterConfig.cs =&gt; "filters.Add(new AuthorizeAttribute());" 中启用了一个过滤器 我刚刚删除了上面的行,现在我的应用程序运行良好。 谢谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-02
    • 2021-01-29
    • 2021-01-07
    相关资源
    最近更新 更多