Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to switch Authentication in MVC Application?

I've created Internet MVC Application with Individual User Accounts Authentication, but now this project should be intranet with windows authentication... How to switch authentication, when project is almost done? I'm not guru in MVC and this is new technology for me, so any help please and if possible with all steps in description=)

like image 983
Bryuk Avatar asked Nov 22 '13 17:11

Bryuk


People also ask

How do I change the authentication in Visual Studio project?

Select File >> New >> select ASP.NET Core Web Application, and change the authentication to Windows Authentication. We can also configure the existing application for Windows Authentication by selecting the option of WA. To configure the authentication manually, open Visual Studio project properties >> go to Debug tab.

How do I change my authentication to individual accounts?

From the ASP.NET project window select "WebAPI". Click on the "Change Authentication" button. From the Change Authentication dialog select "Individual User Accounts". Click on the "OK" button.

How do I add Windows Authentication to an existing MVC project?

By default MVC apps use Form Authentication and Simple Membership, so you need to make it "false" to run Windows Authentication. Select the project name in Solution Explorer and then in the Property Explorer, click to enable Windows Authentication.


2 Answers

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

like image 136
Firearm Avatar answered Sep 21 '22 14:09

Firearm


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.

  1. 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.
  2. 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.
  3. 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, remove handlers. under modules, remove <remove name="FormsAuthentication" />.
  4. Remove the Account and Manage controllers and views. Remove the ManageViewModels from your models.
  5. Under App_Start, get rid of IdentityConfig and Startup.Auth.
  6. At the top level, right next to your web config, is Startup.cs. Get rid of it.
  7. Make a new ApplicationDbContext. It should derive from DbContext. Get rid of throwIfV1Schema: false in your constructors. Then you can get rid of IdentityModels from your Models folder. Add a new migration and update your database.
  8. 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>
like image 20
Adam R. Grey Avatar answered Sep 23 '22 14:09

Adam R. Grey