frosty1
asked on
How to get userid directly after login in
I'm wonder how i can get the userid just after i validate. Is there another method i can use to login than
FormsAuthentication.Redire ctFromLogi nPage(user Name, true);
if (Membership.ValidateUser(u serName, password))
{
// i get a null object on the below as i haven't logged in yet
Guid UserID = new Guid(Membership.GetUser(Us er.Identit y.Name).Pr oviderUser Key.ToStri ng());
// some other logic that requires UserId
}
FormsAuthentication.Redire
if (Membership.ValidateUser(u
{
// i get a null object on the below as i haven't logged in yet
Guid UserID = new Guid(Membership.GetUser(Us
// some other logic that requires UserId
}
Using a login screen on VB.NET, if the login is successful I pass it to a shared module variable on the resulting form, so I can use the current user logged in to display in a status strip.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Frosty1, would you mind explaining why you accepted rkworlds' solution without a point split? Was there a problem with my solution? Is it that you prefer the LoggedIn event rather than the LoggingIn event which fires earlier?
I think your problem was that User.Identity.Name threw a null reference exception. Rkworlds and I solved that the same way.
We both retrieved the userID the same way. I kept your logic to create a new GUID as you didn't explain what you wanted to do with the userID once you got it.
Rkworlds has a fine solution and I know it is too late to split points, but for my future reference I would like to know how to make my solutions more relevant or explain them better, so I'm curious why his solution was preferred.
I think your problem was that User.Identity.Name threw a null reference exception. Rkworlds and I solved that the same way.
We both retrieved the userID the same way. I kept your logic to create a new GUID as you didn't explain what you wanted to do with the userID once you got it.
Rkworlds has a fine solution and I know it is too late to split points, but for my future reference I would like to know how to make my solutions more relevant or explain them better, so I'm curious why his solution was preferred.
ASKER
Sorry wes, seemed to have missed that response. you were spot on. Apologies :)
No problem. Don't worry about it. Have a good day!
Open in new window