简体   繁体   中英

AspNet Membership - Centralizing Logins

Right now we have several databases, each individual database has its own aspnet membership tables. We want to centralize all the membership to one database. For instance a main login page where they will specify the database, username and password. Then we would check on the centralized database and authenticate and redirect them to their account based on the database name they inputed on the textbox.

What is the best way to do this?, there maybe multiple usernames that are the same in different databases and this is my challenge.

ASP.Net Membership has Applications table . As long as you have different application name for different website, you can merge them into one big database; chances of duplicating user id (which is stored as uniqueid) is very low.

When user logins, you need the following 3 fields -

  1. Application (this can be DropDownLis)
  2. Username
  3. Password

Create Own Validation

You cannot use custom Membership Provider to validate user which only accept username and password.

// ValidateUser method doesn't take any additional parameter
public bool ValidateUser(string username, string password)

So you need to implement own validation method to validate user from Merged Database.

Note

If you are redirecting to different website, please take a note of Form Authentication's limitation. For example, it cannot transfer authentication cookie from www.one.com to www.two.com

Are you able to assume that "user123" in database1 and "user123" in database2 are the same individual?

If so, you can just merge as DJ KRAZE suggested. If not, you'll have to create new users for the duplicated user names. You could write a fairly simple SQL script to do this by appending a number to the end of the ID.

Like.... found "john" in database 1, create "john1" user. As I recall, the aspnet_membership database comes with a pretty robust set of stored procedures for creating users and so forth that create all the proper table entries. I would definitely use those, rather than trying to freestyle insert/update statements, if you end up going that route

i believe you can select the database to connect to on your logincontrol. so create a dropdown where users can select the database to connect to and then use that selection as your database. have a look at number 4 on http://forums.asp.net/t/1403132.aspx/1 the selection can be the connectionstring name that specifies the database.

根据我的经验,您能做的最好的事情是在源数据库中为用户名添加重复的前缀,并将合并委托给最终用户。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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