简体   繁体   English

使用Second数据库在MVC中实现授权/身份验证

[英]Using Second database to implement Authorization/Authentication in MVC

I am hoping someone can give me some advice on how to implement a second database to handle user roles and passwords. 我希望有人能给我一些有关如何实现第二个数据库来处理用户角色和密码的建议。 The SQL database schema that contains all of the application data for my site can not be modified in any way. 包含我站点的所有应用程序数据的SQL数据库架构无法以任何方式进行修改。 It does maintain a table with some user info, but nothing for password and role/access level. 它确实维护了一个包含一些用户信息的表,但没有密码和角色/访问级别。 I want this table to be the master, and have a second table in a different DB maintain all the login and role info for each one of the users. 我希望该表成为主表,并在另一个数据库中拥有第二个表,以维护每个用户的所有登录名和角色信息。 How do I go about implementing that in my asp.net-MVC site? 我该如何在asp.net-MVC网站中实现它?

So the problem I was really having was that when ever I tried registering or logging in I would get the SQLServer error - 50. It would never create the DB like it should have. 因此,我真正遇到的问题是,当我尝试注册或登录时,都会出现SQLServer错误-50。它将永远不会创建应有的数据库。 Finally I found this link, and it fixed my problem, SQL Server Express WebLog 最后,我找到了此链接,并解决了我的问题SQL Server Express WebLog

As for using two different databases, I just need the two connection strings in web.config, and two DBcontext classes for the two different connections. 至于使用两个不同的数据库,我只需要web.config中的两个连接字符串,以及两个不同连接的两个DBcontext类。

For the user data: 对于用户数据:

   public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("DefaultConnection")
    {
    }
}

and for all of the application data: 对于所有应用程序数据:

public partial class SomeEntities : DbContext
{
    public SomeEntities()
        : base("name=SomeEntities")
    {
    }
}

and the web.config file: 和web.config文件:

 <connectionStrings>
     <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-SomeScheduler-20150310115216.mdf;Initial Catalog=aspnet-SomeScheduler-20150310115216;Integrated Security=True" providerName="System.Data.SqlClient" />
     <add name="SomeEntities" connectionString="metadata=res://*/Models.Q-MakModel.csdl|res://*/Models.SomeModel.ssdl|res://*/Models.SomeModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=FileServer;initial catalog=SomeDATA;persist security info=True;user id=id;password=idp;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
 </connectionStrings>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM