MVC4 Windows身份验证重定向到帐户/登录 [英] MVC4 Windows Authentication Redirect to Account/Login

查看:306
本文介绍了MVC4 Windows身份验证重定向到帐户/登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设立的 Windows身份验证使用在MVC 4应用程序的的Visual Studio 2013 并使用 IIS防爆preSS开发服务器 。不过,我得到重定向到/帐号/登录(好像我使用窗体身份验证)。

I am setting up Windows Authentication in an MVC 4 application using Visual Studio 2013 and using the IIS Express Development Server. However, I get redirected to /Account/Login (as if I were using forms authentication).

我在我的bin文件夹(或任何地方)没有提及WebMatrix的如下描述:<一href=\"http://stackoverflow.com/questions/5009565/asp-net-mvc3-and-windows-auth-on-iis-keeps-redirecting-to-account-login\">ASP.NET MVC3和Windows身份验证在IIS上不断重定向到/帐号/登录。

I have no reference to WebMatrix in my bin folder (or anywhere) as described here: ASP.NET MVC3 and Windows Auth on IIS keeps redirecting to /Account/Login.

我已经添加了这些条目在web.config的appSettings通过这篇文章的建议:
<一href=\"http://stackoverflow.com/questions/20078482/mvc5-redirects-to-login-aspx-when-using-windows-authentication\">MVC5重定向到的Login.aspx在使用Windows身份验证

I have added these entries to appSettings in the web.config as suggested by this post: MVC5 Redirects to Login.aspx when using Windows Authentication

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

这是我迄今所做的:

Here is what I have done so far:

添加Windows身份验证来的System.Web。

Added windows authentication to system.web.

<authentication mode="Windows"/>

增加了[授权]属性我控制器。我已经使用在web.config中,而不是在控制器上该属性的授权标签(拒绝用户=?),也试过。结果是相同的。

Added the [Authorize] attribute to my controller. I have also tried using the authorization tag in the web.config instead of the attribute on the controller (deny users="?"). The results are the same.

有关在我的项目的开发服务器设置,我改变这些设置:

For the Development Server settings in my project I changed these settings:

匿名身份验证=禁用

Windows身份验证=启用

Windows Authentication = Enabled

我能找到没有提及FormsAuthentication。我想不通为什么它仍然重定向到一个不存在的登录页面。

I can find no reference to FormsAuthentication. I can't figure out why it still redirects to a non-existent login page.

推荐答案

在创建项目可能会使用在你的项目中添加Startup.Auth在App_Start文件夹中的模板已经完成。 (默认模板使用单独的用户帐户,如果你没有将其更改为Windows身份验证作为创造新的ASP.Net Project对话框验证方法)

When the project was created it may have been done using a template that added Startup.Auth in the App_Start folder in your project. (The default template uses Individual User Accounts if you did not change it to windows authentication as the Authentication method in the create new ASP.Net Project dialog)

尝试注释掉这些行,如果他们是present

Try commenting out these lines if they are present

   app.CreatePerOwinContext(ApplicationDbContext.Create);
   app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);


   app.UseCookieAuthentication(new CookieAuthenticationOptions
   {
      AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
      LoginPath = new PathString("/Account/Login"),
      Provider = new CookieAuthenticationProvider
      {
          OnValidateIdentity =  SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
               validateInterval: TimeSpan.FromMinutes(30),
               regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
      }
  });

  app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

或者,如果您还没有添加任何东西到这个文件,你可以完全删除它,并调用它

Or if you have not added anything to this file you could remove it completely and the call to it

        ConfigureAuth(app);

在startup.cs发现,在项目的根

found in the startup.cs in the root of the project

现在大部分的帐户控制器是没有好,如果这种情况下,所以ppared来清理也$ P $使用。

Now most of the account controller is no good to use if this case so be prepared to clean that up also.

这行是web配置重要和正确的。

This line is important and correct in the web config

<authentication mode="Windows"/>

这些行可能不是直接相关的问题,并可以除去

these lines are probably not directly related to the issue and can be removed

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

其他的发展设置也是正确的。

The other development settings are also correct.

这篇关于MVC4 Windows身份验证重定向到帐户/登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆