Question

I'm having the following scenario: I'm working on a multi-tenant application that requires to redirect Database operations to each client DB. So when a user connects to the application, the system uses that client DB to process his actions and operations.

I decided to use the default MVC 4 - SimpleMemberShip provider to handle Membership operations, however, I'm facing the problem that "WebSecurity.InitializeDatabaseConnection method can be called only once".

Thus, I'm trap on using one single DB for all users of the system, even if they have their own Database with SimpleMemberShip tables created on them.

So I'm wondering, Is there a way to either reconnect WebSecutiry.Login each time for SimpleMemberShip, or to dynamically change the DB connection so it goes to the proper client DB to validate user credentials?

Something like:

 WebSecurity. <ChangeConnection> or <ReinitConnection>
 bool result = WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe)
Was it helpful?

Solution

It isn't possible with WebSecurity class.As the error said you can't call InitializeDatabaseConnection method twice. But if you want to use SimpleMembersip Provider you can write your own Custom Membership System and then you can add methods like InitializeDatabase and ReInitializeDatabase or ChangeDatabase etc., however you like.But as i said unfortunately it's not possible with WebSecurity class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top