且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MVC4 Windows身份验证重定向到帐户/登录

更新时间:2022-06-06 22:01:06

在创建项目可能会使用在你的项目中添加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.