如何实现ASP。空MVC项目的NET标识

时间:2022-11-21 03:29:29

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

我创建了一个新的空MVC项目,我想为它添加标识。现在我不知道该怎么做,也不知道如何创建数据库、表和类。我搜索了一下,但是没有找到任何有用的解决方法,我找到了一篇关于添加ASP的文章。现有空ASP的NET标识。NET Web来自而非ASP。Net MVC项目我没有找到。登录注册表单,添加用户到删除用户的角色,如何在我自己的数据库中创建表,如何管理用户

4 个解决方案

#1


65  

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-1

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

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

#2


7  

Open up the nuget package manager by going to:

打开nuget包管理器,如下所示:

Tools > Nuget Package Manager > Package Manager Console

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

在一个新项目[1]。从那里,您可以进入到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.

它将为您安装标识示例。它会问你是否允许它通过按“A”来修改你的webconfig,你接受所有的修改。

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!)

注意:它将更改默认的名称空间,因此通过“查找和替换”,您可以快速地将出现的内容更改为项目名称(注意,您可能需要进入全局名称空间)。在你的my documents文件夹中的aspx页面——在记事本中打开它,并在那里更改名称空间!


[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):

[1]:如果你在开发初期不这样做,你会发现下面的文件会被覆盖(所以要确保你有办法将你的原件与新文件合并):

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'.

#3


0  

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

下面的文章将向您介绍添加ASP的基础知识。您的应用程序的网络身份。http://www.asp.net/identity/overview/getting-started/adding-aspnet-identity-to-an-empty-or-existing-web-forms-project

#4


0  

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

你可以集成ASP。来自NuGet画廊的NET Identity。您可以使用NuGet包管理器控制台安装这些包,如下所示:

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

安装包Microsoft.AspNet.Identity。EntityFramework - version 2.2.1

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

安装包Microsoft.AspNet.Identity。核心- version 2.2.1

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

安装包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.

除此之外,您只需使用默认模板创建一个单独的MVC项目,并在其中创建实现ASP的类和方法。NET identity作为引用,因此也可以在新项目中使用这些类。

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.

如果您正在使用已有的数据库和实体框架,使用数据库优先方法,那么为ASP创建单独的连接字符串和数据上下文。净的身份。使用Edmx作为实体框架使用provider System.Data。EntityClient而ASP。NET标识使用provider System.Data.SqlClient。

#1


65  

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-1

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

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

#2


7  

Open up the nuget package manager by going to:

打开nuget包管理器,如下所示:

Tools > Nuget Package Manager > Package Manager Console

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

在一个新项目[1]。从那里,您可以进入到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.

它将为您安装标识示例。它会问你是否允许它通过按“A”来修改你的webconfig,你接受所有的修改。

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!)

注意:它将更改默认的名称空间,因此通过“查找和替换”,您可以快速地将出现的内容更改为项目名称(注意,您可能需要进入全局名称空间)。在你的my documents文件夹中的aspx页面——在记事本中打开它,并在那里更改名称空间!


[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):

[1]:如果你在开发初期不这样做,你会发现下面的文件会被覆盖(所以要确保你有办法将你的原件与新文件合并):

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'.

#3


0  

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

下面的文章将向您介绍添加ASP的基础知识。您的应用程序的网络身份。http://www.asp.net/identity/overview/getting-started/adding-aspnet-identity-to-an-empty-or-existing-web-forms-project

#4


0  

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

你可以集成ASP。来自NuGet画廊的NET Identity。您可以使用NuGet包管理器控制台安装这些包,如下所示:

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

安装包Microsoft.AspNet.Identity。EntityFramework - version 2.2.1

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

安装包Microsoft.AspNet.Identity。核心- version 2.2.1

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

安装包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.

除此之外,您只需使用默认模板创建一个单独的MVC项目,并在其中创建实现ASP的类和方法。NET identity作为引用,因此也可以在新项目中使用这些类。

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.

如果您正在使用已有的数据库和实体框架,使用数据库优先方法,那么为ASP创建单独的连接字符串和数据上下文。净的身份。使用Edmx作为实体框架使用provider System.Data。EntityClient而ASP。NET标识使用provider System.Data.SqlClient。