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. 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?
-
thats actually Entity framework related question, not related to MVC, added a proper tag.Mladen Oršolić– Mladen Oršolić2015-07-08 22:37:30 +00:00Commented Jul 8, 2015 at 22:37
-
Thanks. I realized that as I was just posting a second question regarding EF.Clint Clark– Clint Clark2015-07-08 22:45:38 +00:00Commented Jul 8, 2015 at 22:45
2 Answers
Take a look at ASP.NET Identity.
http://www.asp.net/identity/overview/getting-started/introduction-to-aspnet-identity
The following should also help:
http://benfoster.io/blog/aspnet-identity-stripped-bare-mvc-part-1
http://benfoster.io/blog/aspnet-identity-stripped-bare-mvc-part-2
1 Comment
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. Finally I found this link, and it fixed my problem, 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.
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:
<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="data source=FileServer;initial catalog=SomeDATA;persist security info=True;user id=id;password=idp;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>