How to switch Authentication in MVC Application?
In the Web.config of you project. The first step would be change:
<authentication mode="Forms">
</authentication>
to
<authentication mode="Windows">
</authentication>
Selecting your project and hitting F4 for the properties window allows you to change the authentication method.
However instead of me putting step by step in here just use this very easy to follow tutorial: Enabling Windows Authentication
Since I found this question through google attempting the same thing, and Firearm's link doesn't quite do the process justice, I'll attempt to list the steps I went through here. Obviously, if I tell you to remove something, that only means if you aren't using it otherwise. I don't think you have to do these steps in any particular order. Also, I'm using Entity Framework, so you'll have to look elsewhere to remove it.
- in the solution explorer, highlight your project and press f4. This will bring up the properties window for that project. Disable anonymous authentication. Enable windows authentication.
- Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution... uninstall anything with "owin" in the name, Microsoft.AspNet.Identity.EntityFramework, and Microsoft.AspNet.Identity.Core.
- Open your Web.config. Under runtime, under assemblyBinding, remove all the dependentAssembly's for Owin stuff that got left behind. Under system.web, replace
<authentication mode="None" />
with<authentication mode="Windows" /> <authorization> <deny users="?" /> </authorization>
. Under system.webServer, removehandlers
. under modules, remove<remove name="FormsAuthentication" />
. - Remove the Account and Manage controllers and views. Remove the
ManageViewModels
from your models. - Under App_Start, get rid of
IdentityConfig
andStartup.Auth
. - At the top level, right next to your web config, is Startup.cs. Get rid of it.
- Make a new ApplicationDbContext. It should derive from DbContext. Get rid of
throwIfV1Schema: false
in your constructors. Then you can get rid ofIdentityModels
from your Models folder. Add a new migration and update your database. - Obviously you'll have to clean out any references you've made yourself to Identity.
Possible additional step: * remove _LoginPartial view. The _Layout view will then be updated to replace partial display of that view with this line:
<p class="nav navbar-text navbar-right">Hello, @User.Identity.Name!</p>