Link to home
Start Free TrialLog in
Avatar of jtuttle99
jtuttle99

asked on

Asp.net logged in another membership provider get null error

If I log in different membership provider, and go to page that contains following code, I get NullReferenceException error. User will be authenticated even if I loggin to different membership.
Is there any ways to prevent from getting error??


If User.Identity.IsAuthenticated Then
  Dim UserIdentity As MembershipUser = Membership.Providers("CustMembershipProvider").GetUser(HttpContext.Current.User.Identity.Name, False)
  Dim currentUserID As String = UserIdentity.ProviderUserKey.ToString()

ASKER CERTIFIED SOLUTION
Avatar of Kumaraswamy R
Kumaraswamy R
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jtuttle99
jtuttle99

ASKER


The code works, but when I logged in correct membership provider, I'm also kicked out of the page.
There are two things that I want to achieve.

1. check if user is authenticated or not
2. if so, check user is logged in correct membership provider

Are there any ways to check if I logged in right membership provider?

Thank you for your help!


Here is my situation. I have membership providers for employee(for maintain contents) and customer.

Customer can't go to employee page, because admin side is protected by roles.

Log in page is only allowed to log in employee log in.

So, the problem is that if employee goes to some customer's side of the web site, this null error happens.

Employee status seem to be authenticated (by employee membership provider), so it passes "If User.Identity.IsAuthenticated then"

 

I would like to know how to escape these codes if user is logged in to employee membership provider.

 

something like this...

If userlogged in employee membership provider then...

 

Anyone??
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial