using FormsIdentity with FormsAuthentication

Results 1 to 2 of 2

Thread: using FormsIdentity with FormsAuthentication

  1. #1
    keith5000 Guest

    Default using FormsIdentity with FormsAuthentication

    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&#039 ;m using FormsAuthentication to authenticate a user&#039;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&#039;m using FormsIdentity directly without having created a variable of that type, but I wouldn&#039;t think it matters. But if I want to create a variable of type FormsIdentity, I have to pass a FormsAuthenticationTicket and I don&#039;t know how to get one of those.<BR><BR>Any ideas?<BR><BR>Thanks in advance,<BR>Keith

  2. #2
    Join Date
    Dec 1969

    Default To get the logged in user's name

    Use:<BR><BR>User.Identity.Name<BR><BR>On a lot of pages for sites/projects I&#039;m working on, I do:<BR><BR>if (User.Identity.Name.Length &#062; 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&#039;ll need to use:<BR><BR>HttpContext.Current.User.Identity.Name <BR><BR>hth

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts