Link to home
Start Free TrialLog in
Avatar of favoretti
favorettiFlag for Netherlands

asked on

ASP.NET Login component with custom membership provider.

Hello experts,

Here's my deal: I'm using ASP.NET Login control in order to Authenticate users. In my codebehind I use a custom membership provider class which implements validateUser() and checks password against an SQL database.

Now, my question is, how can I know in the ASP side of the code, if someone has authenticated, and if someone did, then who?

Thanks.
Avatar of RDdice
RDdice
Flag of United States of America image

You'll need to work with your Identity.

Try looking at Context.User.Identity.IsAuthenticated

and

Context.User.Identity.Name
RDdice;

Is there at difference between Context.User.Identity.IsAuthenticated and me.user.isauthenticated
Yes and No. Effectively its the same. But using Context you can check to see if the user is logged in outside of a Page or a UserControl.

Forinstance if you wanted to create a httpModule  and check to see if a user is logged in you would need to use Context as you don't have access to a page declaration.

Either is fine.
Avatar of favoretti

ASKER

Hrmmh, but COntext object is available only in codebehind, right? I want to check if I'm logged in from the asp part of the code, thus from the "HTML" part. Or am I thinki8ng in the wrong direction now?
ASKER CERTIFIED SOLUTION
Avatar of RDdice
RDdice
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
VB.net version
# Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
#     If Context.User.Identity.IsAuthenticated = True Then
#         LoginDiv.Visible = False
#         divWelcome.Visible = True
#         LoggingInUserName.Text = Context.User.Identity.Name
#     Else
#         LoginDiv.Visible = True
#         divWelcome.Visible = False
#     End If
#    
#    
#     resetError()
# End Sub

Open in new window


 Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
     If Context.User.Identity.IsAuthenticated = True Then
         LoginDiv.Visible = False
         divWelcome.Visible = True
         LoggingInUserName.Text = Context.User.Identity.Name
     Else
         LoginDiv.Visible = True
         divWelcome.Visible = False
     End If
    
    
     resetError()
 End Sub

Open in new window

Aha, that makes it clear. :) Thanks.
Quick and clear. Thanks!