Link to home
Start Free TrialLog in
Avatar of smithmrk
smithmrkFlag for United States of America

asked on

VB.net 2013 - Windows Forms using Membership Validation

OK, this seems simple...but I can't seem to figure it out!

I'm using the AspNetSqlMembershipProvider in my windows form...which works great to login in:
    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        If Membership.ValidateUser(UsernameTextBox.Text, PasswordTextBox.Text) Then
            Me.Close()
            frm_Lookup.Show()
        Else
            MessageBox.Show("Your login attempt was not successful. Please try again.", "Login", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        End If
    End Sub

Once I open the Lookup form based on the fact that their login passed the validation...how do I get the current user name?
For example in ASP.net I can use User.Identity.Name, but what is it in Windows Forms?

Thanks,
Mark
Avatar of Lokesh B R
Lokesh B R
Flag of India image

Hi,

try this

Imports System.Security.Principal
Imports System.Web.Security

Open in new window


Dim name As String =  Thread.CurrentPrincipal.Identity.Name
Dim user As MembershipUser = Membership.GetUser(name)
Dim userName As String = user.UserName

Open in new window

Avatar of smithmrk

ASKER

I tried this:

Thread.CurrentPrincipal.Identity.Name

and it picks up my laptop domain user name...NOT the SQL ASP Membership Provider user name.
I log into my companies domain...however the database (Membership Provider) that I use for my application is different and I'm NOT picking up those user names from: Thread.CurrentPrincipal.Identity.Name

Thanks,
Mark
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland 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
Yes, I was just hoping I could access it the same way I do with ASP.net.

Thanks,
Mark