MVC4 Windows Authentication Redirect to Account/Login

后端 未结 1 1805
离开以前
离开以前 2021-01-03 08:58

I am setting up Windows Authentication in an MVC 4 application using Visual Studio 2013 and using the IIS Express Development Serve

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-03 09:55

    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.Create);
    
    
       app.UseCookieAuthentication(new CookieAuthenticationOptions
       {
          AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
          LoginPath = new PathString("/Account/Login"),
          Provider = new CookieAuthenticationProvider
          {
              OnValidateIdentity =  SecurityStampValidator.OnValidateIdentity(
                   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

    
    

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

    
    
    

    The other development settings are also correct.

    0 讨论(0)
提交回复
热议问题