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.
Use some sort of delimiter and put both users into the the login Identity. e.g. 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. e.g. Hello <% User.Identity.Name %> would display a lot more than you wanted.
would the suggestion outlined here be of any help?
Can SiteB Restrict Access Only to Users Authenticated on Site A? How?
精彩评论