简体   繁体   中英

ASP.NET Membership - Logged into two places at once

We have got two distinct lists of users that we need to power logged in access to sections of our site. These lists can't be combined, as one is synced daily to an externally hosted data source, and both tables have to be 100% the same.

We have set up two Membership providers onto the site, but my question is, is it possible to allow both to be logged in at the same time?

The issue I find is that HttpContext.Current.User.identity.name contains the username of the last successful logon.

would the suggestion outlined here be of any help?

Can SiteB Restrict Access Only to Users Authenticated on Site A? How?

Use some sort of delimiter and put both users into the the login Identity. eg mp3duck/employee1

When you login in via membership provider 1, you would do something like

// extract the existing prov2ID so you can keep it. GetID() would be a string split function
string prov2ID = GetID(User.Identity.Name, 2); 
FormsAuthentication.SetAuthCookie(prov1ID + "/" + prov2ID, false);

And visa versa for a login via membership provider 2.

If you are using the <asp:login> control, you would modify the UserName propery instead of calling SetAuthCookie() since the login control calls SetAuthCookie() itself.

You can put any sort of stuff into the Identity name. I often use it to store both a number int ID for the user primary key, and their username. The only downside is you have to clean it up when displaying it in the html. eg Hello <% User.Identity.Name %> would display a lot more than you wanted.

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