1

I am trying to do the same thing as the poster for the question below, that is to share the user database from ASP .NET Identity and use it for user login in another Windows Form application.

ASP.NET Identity login

My question is a follow up from the response given in that link: how do I ensure that the Microsoft.Identity.EntityFramework in the windows form is connecting to my ASP .NET user database? That is to say, how can I check its connection strings to ensure that it's the right database?

Or is there a better or a more intuitive way to implement .NET Identity in Windows Form?

My apology if this question seems redundant. But I am having a really hard time on this and any explanation is greatly appreciated.

Thanks

7
  • Do you have direct access to this database? For an example, when the ASP.NET system is in production environment, will you be able to access the database from the pc where winforms app is installed? Commented Jan 11, 2016 at 4:18
  • Yes, I have direct access to the database from both ASP .NET and the Winform application. I actually managed to retrieve the username from the database using basic SQL query, but what I needed to do now is to verify its password. Commented Jan 11, 2016 at 4:28
  • Have you tried the solution given in the link? As far as I can see it should work in your case too. Commented Jan 11, 2016 at 4:31
  • Yes, I have, and it didn't work. I suspect it's because I didn't specify the connection string for the EntityFramework to determine which database to connect to. Commented Jan 11, 2016 at 4:40
  • If you want you can hard code the connection string and test it. Later you can add it to the config file. Commented Jan 11, 2016 at 4:43

2 Answers 2

1

Old Question, but has no answer.

how can I check its connection strings to ensure that it's the right database?

Add ADO.NET Entity Data Model to the project that contain connection to IdentityDatabase.

It will generate POCO classes for 4 tables and a context class

AspNetRole AspNetUser AspNetUserClaim AspNetUserLogin 

check connectivity:

For a context class named WebFormsIdentityEntities:

 WebFormsIdentityEntities context = new WebFormsIdentityEntities(); Console.WriteLine(context.AspNetUsers.Count()); 

it should return data , otherwise raise Exception for connectivity error.

Sign up to request clarification or add additional context in comments.

Comments

0

Why not create a new context on WinForm project? Link , or create a DLL library for connection to database, then reference to this on your two projects,

I have similar projects today. I have an ASP.Net-MVC and a WinForm projects and a library for context and models, I made a library with models, migrations and context. I then added references to the library in my two projects, the only thing I have to do is add the connection string in both projects at App.Config or Web.Config and add references to EntityFramework and Asp.net-identity NugetPackages.

This is my code on WinForm to validate login, it is a void on Program Class:

 public ApplicationUserManager UsrMan = new ApplicationUserManager(new ApplicationUserStore(new libProduccionDataBase.Contexto.DataBaseContexto())); public void CheckLogin( bool change = false ) { using (var loginfrm = new LogInForm()) { if (loginfrm.ShowDialog() == DialogResult.OK) { var t = Auxiliares.Validate(loginfrm.Response); if (t.isValid && UsrMan.FindByName( loginfrm.Response.UserName ) != null && UsrMan.CheckPassword( UsrMan.FindByName( loginfrm.Response.UserName ), loginfrm.Response.Password ) ) { Program.User = UsrMan.FindByName( loginfrm.Response.UserName ); } else { if (!t.isValid) { var str = new System.Text.StringBuilder(); t.Result.ToList().ForEach( err => { str.AppendFormat( "• {0}\n", err.ErrorMessage ); } ); MessageBox.Show( str.ToString(), "Error...", MessageBoxButtons.OK, MessageBoxIcon.Error ); } CheckLogin(); } } else { if (!change) ExitThread(); } } } 

This is the class for userManager:

public class ApplicationUserManager : UserManager<ApplicationUser, int> { public ApplicationUserManager( IUserStore<ApplicationUser, int> store ) : base( store ){} } 

And the userStore (I use this because I personalize the id for user to int):

 public class ApplicationUserStore : UserStore<ApplicationUser, ApplicationRole, int, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim> { public ApplicationUserStore(Contexto.DataBaseContexto context) : base(context) { } } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.