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

时间:2015-08-21 12:03:18

标签: c# asp.net asp.net-mvc asp.net-mvc-4 authentication

我使用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>
    

  1. 在控制面板中打开“程序和功能”
  2. 选择“转弯 Windows功能打开或关闭“。
  3. 导航到Internet信息服务&gt;万维网服务&gt;安全性并确保选中 Windows身份验证节点
  4. 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

    正如你所知,我得到了一个无限的重定向循环,这可能就是为什么我无法让它工作的原因。但我确实不知道是什么导致了它。非常感谢任何帮助。

2 个答案:

答案 0 :(得分:6)

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

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

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

答案 1 :(得分:1)

您还可以检查C:\ Users [您的用户名] \ Documents \ IISExpress \ Logs [应用程序名称],查看请求期间使用的任何错误详细信息或URL。