简体   繁体   English

如何在ASP.NET身份(WebForms)中使用我自己的数据库

[英]How to use my own database in ASP.NET Identity (WebForms)

I try to make a simple web application. 我尝试制作一个简单的Web应用程序。 There will be very few users(one or two). 用户很少(一两个)。 No need to make complicated membership stuff. 无需复杂的会员资格。 I need just basic login process. 我只需要基本的登录过程。 I use Visual Studio 2013 我使用Visual Studio 2013

I made some research on the internet and found something about ASP.NET Identity. 我在互联网上做了一些研究,发现了一些关于ASP.NET身份的东西。 However i could not found anything about how to install Identity tables to my own mssql database. 但是我找不到任何关于如何将Identity表安装到我自己的mssql数据库的内容。

I used ASP.NET membership before and it was easy to install tables by using aspnet_regsql.exe and adding some codes to web.config 之前我使用过ASP.NET成员资格,使用aspnet_regsql.exe并在web.config中添加一些代码很容易安装表

But now i am really confused with Identity stuff. 但现在我真的很困惑身份的东西。 It uses a default database to store users. 它使用默认数据库来存储用户。 But in my server there will be my sql database that stores both my datas and user datas. 但是在我的服务器中会有我的sql数据库存储我的数据和用户数据。

How can i combine these two databases into one? 我如何将这两个数据库合二为一? How can I install Identity tables to my own database and configure my Project to use it? 如何将Identity表安装到我自己的数据库并配置我的Project以使用它?

It sounds like you just want the Identity tables to use the same database as the rest of your application. 听起来您只是希望Identity表使用与应用程序其余部分相同的数据库。 If you're using a new Identity project in Visual Studio 2013, it should be using Entity Framework, which simplifies things significantly. 如果您在Visual Studio 2013中使用新的Identity项目,则应使用Entity Framework,这可以显着简化操作。

You should be able to make this happen by making sure the Identity code uses the same connection string as your own database context. 您应该能够通过确保Identity代码使用与您自己的数据库上下文相同的连接字符串来实现此目的。 If you change the "DefaultConnection" string in Web.config to point to your own database, Entity Framework will take care of the rest. 如果将Web.config中的“DefaultConnection”字符串更改为指向您自己的数据库,则Entity Framework将负责其余的工作。

If you got rid of the "DefaultConnection" connection, you can change the string used in IdentityModels.cs (in the Models folder of your project) to be your custom string. 如果删除了“DefaultConnection”连接,则可以将IdentityModels.cs中使用的字符串(在项目的Models文件夹中)更改为自定义字符串。 Look for: 寻找:

public ApplicationDbContext()
        : base("DefaultConnection", throwIfV1Schema: false)

and change the string in base(). 并更改base()中的字符串。

Again, the magic of Entity Framework is that it'll automatically create the tables and relationships it needs without requiring you to build them yourself. 同样,Entity Framework的神奇之处在于它会自动创建所需的表和关系,而无需您自己构建它们。 EF6 is also really good about handling versioning when there are multiple contexts, so you shouldn't get any "model changed" errors unless you got rid of the __MigrationHistory table. 当有多个上下文时,EF6也非常适合处理版本控制,所以除非你摆脱了__MigrationHistory表,否则你不应该得到任何“模型改变”的错误。

You should use Entity Framework you can take different approach like code first ,Model First DB First. 您应该使用Entity Framework,您可以采用不同的方法,如代码优先,Model First DB First。

It will make much easier process for you. 它将为您提供更轻松的流程。

Here is some good links. 这是一些很好的链接。

How to install 如何安装

http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net- MVC应用程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以在自己的用户数据库中使用ASP.NET WebForms中的成员资格提供程序吗? 如果是这样,怎么办? - Can I use the Membership provider in ASP.NET WebForms with my own User database? If so, how? 将自己的表放在ASP.net Identity Framework数据库中 - Putting my own tables in ASP.net Identity Framework Database 如何为 ASP.NET Identity 2 生成我自己的主键 - How to generate my own primary key for ASP.NET Identity 2 使用WebForms的ASP.Net Identity到现有SQL数据库 - ASP.Net Identity with WebForms to existing SQL database 如何将ASP.NET Identity与您自己的自定义表一起使用 - How to Use ASP.NET Identity with your own Custom Table 不能在 ASP.NET 核心中使用我的 MySql 数据库和身份 - cant use my MySql database in ASP.NET Core with Identity 如何在asp.net webforms中使用HttpClient - How to use HttpClient in asp.net webforms Webforms和Oracle的Asp.NET身份 - Asp.NET Identity with Webforms and Oracle 如何将Asp.net身份与数据库一起使用 - how to Use Asp.net Identity with DataBase first approach 如何在ASP.NET Webforms网站项目中一起使用Webforms和ASP.NET MVC? - How do I use Webforms and ASP.NET MVC together in an ASP.NET Webforms Website project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM