To check whether the user has logged in or not a simple 2 lines to be checked in our application
using System.Security.Principal //namespace to be used
IPrincipal principal = HttpContext.Current.User; //gives the current user logged in
return principal.Identity.IsAuthenticated; //isauthenticated gives return true or false
so if user has logged in then it returns true and vice versa , the userid of the logged in user can be retrieved in the below manner
userId = new Guid(Membership.GetUser(Page.User.Identity.Name).ProviderUserKey.ToString());
No comments:
Post a Comment