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

Cia*_*ian 4 c# asp.net authentication asp.net-mvc asp.net-mvc-4

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

项目属性

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

Web.config文件

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

    <system.webServer>
        <security>
          <requestFiltering>
            <requestLimits maxUrl="10999" maxQueryString="2097151" />
          </requestFiltering>
        </security>
    </system.webServer>
    
    Run Code Online (Sandbox Code Playgroud)

视窗

  1. 在控制面板中打开"程序和功能".
  2. 选择" 打开或关闭Windows功能".
  3. 导航到Internet信息服务>万维网服务>安全性,并确保选中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.
Run Code Online (Sandbox Code Playgroud)

这是IIS错误页面中的URL:

HTTP://本地主机:52728 /帐号/登录?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%25252525252525252525252FAc计数%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%25252525252525252525252525252525252525252F525252525252525252FAccount%252525252525252525252525252525252525252FLogin%252525252525252525252525252525252525253FReturnUrl%252525252525252525252525252525252525253D%25252525252525252525252525252525252525252F525252525252525252FAccount%252525252525252525252525252525252525252FLogin%252525252525252525252525252525252525253FReturnUrl%252525252525252525252525252525252525253D%25252525252525252525252525252525252525252F

你可以告诉我得到一个无限的重定向循环,这可能就是我无法让它工作的原因.但我确实不知道是什么导致了它.任何帮助是极大的赞赏.

Cia*_*ian 7

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

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

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