MVC4 Windows Authentication Redirect to Account/Login

霸气de小男生 提交于 2019-12-03 17:09:34

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)

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);

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

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!