0

I'm working on building a simple MVC application which has some pages which non-registered users should be able to view and others that only registered users should be able to view. I have already developed a large part of the application, and only now have I started to think about authentication. I want to use ASP.NET Identity, but I can't figure out how to add it to this application. All of the tutorials I can find rely on starting with the template in Visual Studio. How can I modify my application to add this authentication?

Merlin04
  • 1,837
  • 4
  • 23
  • 27
  • Possible duplicate of [Allow access for unathenticated users to specific page using ASP.Net Forms Authentication](https://stackoverflow.com/questions/3628445/allow-access-for-unathenticated-users-to-specific-page-using-asp-net-forms-authe) – Ryan Wilson Jun 15 '19 at 19:10
  • Please see the duplicate link I added. – Ryan Wilson Jun 15 '19 at 19:10
  • That doesn't apply to ASP.NET Identity. In addition, it doesn't say how to set up the authentication. – Merlin04 Jun 15 '19 at 19:19
  • Yes it is, ASP.NET Identity is based on either Forms Authentication or Windows Authentication, which in turn then gives an Identity to an Authenticated user. (https://learn.microsoft.com/en-us/aspnet/identity/overview/getting-started/introduction-to-aspnet-identity) – Ryan Wilson Jun 15 '19 at 19:21
  • Ok, but how do I set it up on my page? – Merlin04 Jun 15 '19 at 19:27
  • Is your website external or internal (intranet)? – Ryan Wilson Jun 15 '19 at 19:34
  • Right now it's just running on my laptop but once it's done it will be external. – Merlin04 Jun 15 '19 at 19:35
  • Then you are going to want to use Forms Authentication for your website. Please see this link, you are also going to need a database for storing ASP.NET Identities (http://techfunda.com/howto/255/create-forms-authentication-in-asp-net-mvc) – Ryan Wilson Jun 15 '19 at 19:39
  • That link is based on the default project template, which I am not using. – Merlin04 Jun 15 '19 at 19:45
  • Try this then (https://stackoverflow.com/questions/31960433/adding-asp-net-mvc5-identity-authentication-to-an-existing-project) – Ryan Wilson Jun 15 '19 at 19:46
  • That looks like it might work, but I'm a bit confused about it. When it says "Add a user class and with IdentityUser inheritance", what file do I put that in? In addition, it says "Change your DbContext parent from DbContext to IdentityDbContext", what is the DbContext parent and what file is that in? – Merlin04 Jun 15 '19 at 20:02
  • Sorry for the late response, but I had to go a few places this evening, this should help with the DBContext (https://learn.microsoft.com/en-us/previous-versions/aspnet/dn468175(v%3Dvs.108) and this should help with IdentityUser (https://learn.microsoft.com/en-us/previous-versions/aspnet/dn468178(v=vs.108) both are inside the namespace `Microsoft.AspNet.Identity` – Ryan Wilson Jun 16 '19 at 02:01
  • I've gotten around to trying to add this, but I'm still confused about some aspects of the answer. What folder do I put the classes that I'm supposed to create in? – Merlin04 Jun 26 '19 at 01:32
  • Any folder you like, just so long as it is accessible by the project, I typically create a folder named `Classes` and store class objects specific to the project inside of it. – Ryan Wilson Jun 26 '19 at 12:44

0 Answers0