How can you tell is current user is authenticated within an ascx?

From: David C. Adler (dcadler@adlercomputing.com)
Date: 08/20/02


From: "David C. Adler" <dcadler@adlercomputing.com>
Date: Tue, 20 Aug 2002 12:56:22 -0500


I have a user control that I use for header graphics and navigation. My site
uses forms authentication to authenticate users. I want to dynamically
control the menu layout, plus instace login status, based upon whether the
current user has been authenticated. From within my aspx.vb pages, I use the
following code to determine if the user is authenticated and to get the
current users Name value from the Authentication Ticket.

'Retrieve MemberID from Authentication cookie
Private Function GetMemberID() As Integer
    Dim objUserIdentity As FormsIdentity
    Dim strMemberID As String
    If User.Identity.IsAuthenticated Then
        objUserIdentity = User.Identity
        strMemberID = objUserIdentity.Name
        GetMemberID = CType(Trim(strMemberID), Integer)
    Else
        GetMemberID = 0
    End If
End Function

The function works fine in an aspx.vb page but if I put the same code in an
ascx.vb page, I get an error that says...

Name "User" is not declared and references the following line in my code...

    If User.Identity.IsAuthenticated Then

What am I missing here?

I dont want to have to add code to all of my 130+ aspx.vb pages in my site
to control the menu like I want. It seems as though I should be able to do
this from the ascx or ascx.vb code and only have to coe it once.

Thanks in advance for any help you can offer.

Dave Adler



Relevant Pages

  • San Diego .NET Developer Group Meeting (FEB 6th 2007)
    ... Using Forms Authentication with SharePoint 2007: ... and control access to your site ... Automating Builds with MSBuild and Team Foundation Server: ...
    (microsoft.public.dotnet.general)
  • Re: Access Control problems
    ... You need to configure 2 things for access control ... after authentication, ... the ntfs permission of files / folder. ... Configure IIS 5.0 Web Site Authentication in Windows 2000 ...
    (microsoft.public.inetserver.iis.security)
  • Re: Composite Control need write permisson
    ... If a control needs write access, then the permissions on the directory ... or has a process in place that let's you request particular ... Integrated Windows Authentication may cause some ...
    (microsoft.public.dotnet.framework.aspnet.buildingcontrols)
  • Re: VB code to check POP3 account
    ... >> the POP3 server uses one of the alternative authentication methods. ... While easier & providing a control I could use for other ... >> know at least Pro had the winsock control available. ...
    (comp.lang.basic.visual.misc)
  • Re: Forms Authentication without Login Page
    ... Thanks Brad! ... the authentication seems to be delayed by one page view: ... hit Login in my login control. ... and my login control calls ...
    (microsoft.public.dotnet.framework.aspnet.security)

Quantcast