ASP.NET MVC Windows身份验证拒绝工作

本文关键字:拒绝 工作 身份验证 Windows NET MVC ASP | 更新日期: 2023-09-27 18:09:10

我使用Visual Studio 2015创建了一个MVC Web应用程序。我的目标是根据需要将身份验证模式从无更改为Windows身份验证,这样我就可以使用@User.Identity.Name方法来识别用户。到目前为止我尝试过的东西的简短总结:

项目属性

  • 设置匿名身份验证:禁用
  • 设置Windows身份验证:已启用

Web.config

  • maxUrlLength="65536">属性添加到httpRuntime标记
  • maxQueryStringLength="10240">属性添加到httpRuntime标记
  • <system.web>标签中添加<authentication mode="Windows"/>
  • 添加system.webServer标记(每当我添加它时,它都会以ERR_TOO_MANY_DIRECTS结束(:

    <system.webServer>
        <security>
          <requestFiltering>
            <requestLimits maxUrl="10999" maxQueryString="2097151" />
          </requestFiltering>
        </security>
    </system.webServer>
    

Windows

  1. 在"控制面板"中打开"程序和功能">
  2. 选择">转弯Windows功能打开或关闭"。
  3. 导航到Internet Information Services>World Wide Web Services>Security,并确保已选中Windows身份验证节点

IIS Express

我尝试从头开始创建一个新项目,并在项目设置过程中巧妙地选择了Windows身份验证。这很好,所以我相信我的IISExpress设置是100%正确的。我甚至检查了applicationhost.config文件,但它没有我的特定项目的条目。同样,如果在创建新项目时选择正确的身份验证,它也可以正常工作。


以上似乎都不起作用,当我尝试运行Visual Studio项目时,所有这些都会出现IIS错误:

HTTP Error 404.15 - Not Found
The request filtering module is configured to deny a request where the query string is too long.

这就是IIS错误页面中的URL:

http://localhost:52728/Account/Login?ReturnUrl=%2FAccount%2FLogin%3FReturnUrl%3D%252FAccount%252FLogin%253FReturnUrl%253D%25252FAccount%25252FLogin%25253FReturnUrl%25253D%2525252FAccount%2525252FLogin%2525253FReturnUrl%2525253D%252525252FAccount%252525252FLogin%252525253FReturnUrl%252525253D%25252525252FAccount%25252525252FLogin%25252525253FReturnUrl%25252525253D%2525252525252FAccount%2525252525252FLogin%2525252525253FReturnUrl%2525252525253D%252525252525252FAccount%252525252525252FLogin%252525252525253FReturnUrl%252525252525253D%25252525252525252FAccount%25252525252525252FLogin%25252525252525253FReturnUrl%25252525252525253D%2525252525252525252FAccount%2525252525252525252FLogin%2525252525252525253FReturnUrl%2525252525252525253D%252525252525252525252FAccount%252525252525252525252FLogin%252525252525252525253FReturnUrl%252525252525252525253D%25252525252525252525252FAccount%25252525252525252525252FLogin%25252525252525252525253FReturnUrl%25252525252525252525253D%2525252525252525252525252FAccount%2525252525252525252525252FLogin%2525252525252525252525253FReturnUrl%2525252525252525252525253D%252525252525252525252525252FAccount%252525252525252525252525252FLogin%252525252525252525252525253FReturnUrl%252525252525252525252525253D%25252525252525252525252525252FAccount%25252525252525252525252525252FLogin%25252525252525252525252525253FReturnUrl%25252525252525252525252525253D%2525252525252525252525252525252FAccount%2525252525252525252525252525252FLogin%2525252525252525252525252525253FReturnUrl%2525252525252525252525252525253D%252525252525252525252525252525252FAccount%252525252525252525252525252525252FLogin%252525252525252525252525252525253FReturnUrl%252525252525252525252525252525253D%25252525252525252525252525252525252FAccount%25252525252525252525252525252525252FLogin%25252525252525252525252525252525253FReturnUrl%25252525252525252525252525252525253D%2525252525252525252525252525252525252FAccount%2525252525252525252525252525252525252FLogin%2525252525252525252525252525252525253FReturnUrl%2525252525252525252525252525252525253D%252525252525252525252525252525252525252FAccount%252525252525252525252525252525252525252FLogin%252525252525252525252525252525252525253FReturnUrl%252525252525252525252525252525252525253D%25252525252525252525252525252525252525252F

正如你所知,我得到了一个无限的重定向循环,这可能是我无法使其工作的原因。但是我不知道是什么原因造成的。我们非常感谢您的帮助。

ASP.NET MVC Windows身份验证拒绝工作

我想我能回答自己的问题了,因为我刚刚开始工作。对于将来遇到类似错误的人来说,这可能会派上用场。

解决方案:我不得不在App_Start/Startup.Auth.cs:中注释掉以下代码

 app.UseCookieAuthentication(new CookieAuthenticationOptions
    {
        AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
        LoginPath = new PathString("/Account/Login")
    });
    app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

您还可以检查C:''Users[Your UserName]''Documents''IISExpress''Logs[Application Name]以了解请求过程中使用的任何错误详细信息或URL。