Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to implement ASP.NET Identity to an empty MVC project

I create a new empty MVC project and I want to add identity to it. Now I do not know how to do this and how to create database and tables and classes. I searched but I did not find any useful solution for my question, I found an article for adding ASP.NET Identity to an existing empty ASP.NET Web from but for ASP.Net MVC project I did not find.
for log in
for registration form
for adding a user to role
for deleting user
how to create tables in my own database
how to manage users

like image 940
Kamran Sadin Avatar asked Mar 08 '14 18:03

Kamran Sadin


4 Answers

I was looking for the same thing and the following blog posts helped me with this:

http://benfoster.io/blog/aspnet-identity-stripped-bare-mvc-part-1

http://benfoster.io/blog/aspnet-identity-stripped-bare-mvc-part-2

like image 60
Ganhammar Avatar answered Nov 12 '22 19:11

Ganhammar


Open up the nuget package manager by going to:

Tools > Nuget Package Manager > Package Manager Console

in a new project[1]. From there, You can enter next to the PM>

Install-Package Microsoft.AspNet.Identity.Samples -Pre 

which will install the Identity sample for you. It will ask you if you allow it to alter your webconfig by pressing 'A' you accept all changes.

From then onwards, you'll have the sample identity project installed!

Note: It will change the default namespace, so by going to 'find and replace' you can quickly alter the occurrences to your project name (note, you may have to go into your global.aspx page in your my documents folder - open it in notepad and change the namespace there too!)


[1]: If you do not do this at the beginning of your development, you will find that the following files will be overwritten(so make sure you have a way to merge your originals with the new):

Overwrite existing file 'Views\Web.config'.
Overwrite existing file 'Views\Shared\Error.cshtml'.
Overwrite existing file 'Views\Shared\_Layout.cshtml'.
Overwrite existing file 'Views\Home\Index.cshtml'.
Overwrite existing file 'Views\_ViewStart.cshtml'.
Overwrite existing file 'Global.asax.cs'.
Overwrite existing file 'Global.asax'.
Overwrite existing file 'Controllers\HomeController.cs'.
Overwrite existing file 'Content\Site.css'.
Overwrite existing file 'App_Start\RouteConfig.cs'.
Overwrite existing file 'App_Start\FilterConfig.cs'.
Overwrite existing file 'App_Start\BundleConfig.cs'.
like image 28
jbutler483 Avatar answered Nov 12 '22 18:11

jbutler483


The following article explains you the basics of adding ASP.NET Identity to your application. http://www.asp.net/identity/overview/getting-started/adding-aspnet-identity-to-an-empty-or-existing-web-forms-project

like image 1
pranav rastogi Avatar answered Nov 12 '22 20:11

pranav rastogi


You can integrate ASP.NET Identity from the NuGet gallery. You can install these packages using the NuGet Package Manager Console, like this:

Install-Package Microsoft.AspNet.Identity.EntityFramework –Version 2.2.1

Install-Package Microsoft.AspNet.Identity.Core -Version 2.2.1

Install-Package Microsoft.AspNet.Identity.OWIN -Version 2.2.1

Apart from that, you just create a separate MVC project with the default template and where you have classes and methods for implementation of ASP.NET identity as a reference so just use these classes in your new project as well.

If you are using existing database with Entity Framework with Database first approach then create the separate connection string and data context for ASP.NET identity.As Entity Framework with Edmx uses the provider System.Data.EntityClient while ASP.NET Identity uses the provider System.Data.SqlClient.

like image 1
Sandeep Shekhawat Avatar answered Nov 12 '22 18:11

Sandeep Shekhawat