using FormsIdentity with FormsAuthentication

nico22

New Member
In short:<BR>How can I use the FormsIdentity class (or any other method) to determine if a user has already been authenticated using FormsAuthentication?<BR><BR><BR>Details:<BR>I'm using FormsAuthentication to authenticate a user's login in an intranet website. However if the user inadvertently comes back to the login page while still logged in, I want to be able to check that they are authenticated and then redirect them back inside the site before displaying the login form.<BR><BR>I thought I could use the FormsIdentity class (under System.Web.Security) to do this as follows:<BR><BR> sub Page_Load (source as Object, e as EventArgs)<BR> <BR> if (FormsIdentity.IsAuthenticated) then<BR> Response.Redirect ("/home.aspx")<BR> end if<BR> <BR> end sub<BR><BR><BR>except i get this compilation error on the line with FormsIdentity.IsAuthenticated:<BR>"This reference to a non-shared member requires an object reference, and none is supplied"<BR><BR>I'm using FormsIdentity directly without having created a variable of that type, but I wouldn't think it matters. But if I want to create a variable of type FormsIdentity, I have to pass a FormsAuthenticationTicket and I don't know how to get one of those.<BR><BR>Any ideas?<BR><BR>Thanks in advance,<BR>KeithUse:<BR><BR>User.Identity.Name<BR><BR>On a lot of pages for sites/projects I'm working on, I do:<BR><BR>if (User.Identity.Name.Length > 0)<BR> // assume user is logged in<BR>else<BR> // user is not logged in<BR><BR>Hope this helps. Also note that the User object is a property of the HttpContext class, so if you are trying to retrieve this information in a User Control or component, you'll need to use:<BR><BR>HttpContext.Current.User.Identity.Name<BR><BR>hth
 
Back
Top