简体   繁体   English

ASP .NET MVC数据库第一个个人用户帐户

[英]ASP .NET MVC Database First Individual User Accounts

I am developing a large MVC Web Application with ASP .NET. 我正在使用ASP .NET开发大型MVC Web应用程序。 I make it as Database First, not Code First. 我将其设置为“数据库优先”,而不是“代码优先”。

By creating the Web App with Individual User Accounts Authentication it creates the models, views, controllers and the database for it, which is pretty nice 通过使用单个用户帐户身份验证创建Web应用,它可以为其创建模型,视图,控制器和数据库。

But I want to change the migration to use my hosted database in the cloud. 但是我想更改迁移以在云中使用托管数据库。 I tried to change [base("DefaultConnection",...)] in the IdentityModel.cs to use the hosted database, and I also tried to make changes on the Web.config 我试图在IdentityModel.cs更改[base("DefaultConnection",...)]以使用托管数据库,并且我还尝试在Web.config上进行更改

It was not a good idea! 这不是一个好主意! :D :D

Please, help me! 请帮我!

You just need to search for the "DefaultConnection" ConnectionString in your Web.config file, replace it with your remote server's information and that should be enough to connect to your hosted database. 您只需要在Web.config文件中搜索“ DefaultConnection” ConnectionString,将其替换为远程服务器的信息即可,这足以连接到托管数据库。

It should look like this: 它看起来应该像这样:

<add name="DefaultConnection" connectionString="data source=**YourServer**;initial catalog=**YourDatabaseName**;user id=**DatabaseUsername**;password=**DatabasePassword**" providerName="System.Data.SqlClient" />

I working on a project like you do. 我像您一样从事一个项目。 I'm using Database First Approach. 我正在使用数据库优先方法。 After create a project with Individual User Authentication, you need to transfer these user tables to your database. 使用个人用户身份验证创建项目后,您需要将这些用户表传输到数据库中。 You can do this with schema compare. 您可以使用架构比较来做到这一点。

On the SQL Server Object Explorer > find your localdb that contain user tables > right click > Schema Compare SQL Server Object Explorer >找到包含用户表的localdb>右键单击> Schema Compare

schema compare 模式比较

Then select target (your database) and click Compare on right corner. 然后选择目标(您的数据库),然后单击右上角的Compare

Select table(s) you want to transfer to your database. 选择要转移到数据库的表。

After doing this edit Web.config file: 完成此编辑Web.config文件后:

<add name="DefaultConnection" connectionString="Data Source=YourServerName;Initial Catalog=YourDatabaseName;Integrated Security=True" providerName="System.Data.SqlClient" />

(This connectionString is to use default model, controllers and actions provided by project. If you want to create your own functions for user operations you only need to add below line after transfer tables.) (此connectionString用于使用项目提供的默认模型,控制器和操作。如果要为用户操作创建自己的函数,则只需在传输表之后添加以下行。)

Here, provider name is important. 在此,提供商名称很重要。 Don't chance it. 不要碰碰运气 This connection string is for user operations. 此连接字符串用于用户操作。

Then add ADO.NET Entity Data Model to use your other tables with Entity framework 然后添加ADO.NET实体数据模型以将其他表与Entity Framework一起使用

<add name="YourEntityName" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=YourServerNameL;initial catalog=YourDBName;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />

providerName is important here as well. providerName在这里也很重要。

  1. I add my ado.net in (model folder) 我在(模型文件夹)中添加ado.net

  2. on the web.config change my new connection string to "DefaultConnection" 在web.config上,将新的连接字符串更改为“ DefaultConnection”

  3. in the Dbcontext "my ado.net" change to : base("DefaultConnection") 在Dbcontext“ my ado.net”中更改为:base(“ DefaultConnection”)

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

相关问题 个人用户帐户在ASP.Net MVC中不进行身份验证 - Individual User Accounts to No Authentication in ASP.Net MVC .Net Core 3.1 MVC 身份验证个人用户帐户和 ASP.NET 核心项目中的脚手架身份 - .Net Core 3.1 MVC Authentication Individual User Accounts and Scaffold Identity in ASP.NET Core projects 一对多MVC个人用户帐户 - One-to-many MVC Individual User Accounts MVC 个人用户帐户登录值持久化 - MVC Individual User Accounts login value persisting 数据库(ASP.NET MVC)中已经有一个名为“ Accounts”的对象 - Already an object named “Accounts” in the database (ASP.NET MVC) Asp.net Web应用程序个人帐户 - Asp.net Web Application individual accounts 在ASP.Net MVC应用程序中将身份验证从个人帐户更改为Windows(Intranet) - Changing Authentication from individual accounts to Windows (Intranet) in ASP.Net MVC app 使用ASP.NET用户帐户登录的外部数据库 - External Database for login with ASP.NET User Accounts ASP.NET MVC 5 Web应用程序中是否应该只有一个DbContext和数据库才能将用户帐户与对象相关联? - Should there be single DbContext and Database within the ASP.NET MVC 5 Web Application to be able associate User's Accounts with objects? 如何在 Asp.NET Core 中的个人用户帐户之间添加一对多关系 - How to add one to many relationship between Individual user accounts in Asp.NET Core
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM