【问题标题】:Windows Authentication not working in ASP.NET MVC 5 web appWindows 身份验证在 ASP.NET MVC 5 Web 应用程序中不起作用
【发布时间】:2014-04-24 05:08:31
【问题描述】:

我有一个 ASP.NET MVC 5 应用程序并尝试启用 Windows 身份验证。开发机器是Windows Server 2008 R2、IIS Express 8.0、Visual Studio 2013 & .NET Framework 4.5。

我在浏览应用程序时收到 404 Not Found 错误。应用通过 http://localhost:63455/Account/Login?ReturnUrl=%2F 进入重定向循环。最终,ReturnUrl 最终会变得非常大,因为它会被附加到每个重定向中。

我的 web.config 如下所示:

  <system.web>
    <authentication mode="Windows"/>
  </system.web>

我已尝试在开发服务器属性上设置 匿名身份验证Windows 身份验证设置。

我也尝试添加以下appSettings

<add key="autoFormsAuthentication" value="false"/>
<add key="enableSimpleMembership" value="false"/>

如何让 Windows 身份验证正常工作?

【问题讨论】:

    标签: asp.net-mvc-5 windows-authentication windows-server-2008-r2 iis-express


    【解决方案1】:

    Startup.Auth.cs 中的 ConfigureAuth 方法包含以下代码,需要将其删除以进行 Windows 身份验证

    代码用于表单验证OWIN

            // Enable the application to use a cookie to store information for the signed in user
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                LoginPath = new PathString("/Account/Login")
            });
            // Use a cookie to temporarily store information about a user logging in with a third party login provider
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
    

    【讨论】:

    • 嗨,谢谢。有没有办法可以使用 cookie 和 windows 身份验证?基本上我需要使用 OWIN 添加额外的声明。但是当启用 Windows 身份验证时,它似乎不允许添加声明。
    【解决方案2】:

    只是提个醒。尽管我确实删除了 externalsignincookie,但您不必完全删除 cookie 身份验证。看看我在https://github.com/vishnu4/AspNetMVC5WinAuth 的项目,我在其中使用 OWIN 和 MVC5 来使用 Windows 身份验证。希望这可以帮助其他试图让它工作的人。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-01
      • 1970-01-01
      • 2016-11-06
      • 2014-02-05
      • 2017-09-24
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      相关资源
      最近更新 更多