how to pull active directory login id using vb form

I am using visual studio 2005 to try and create a web form which will pull the active directory id or name from a user when the form loads and place the value in a text box. I am not even sure where to start here. Any help would be appreciated.

thanks,
d-bass
D-bassAsked:
Who is Participating?
 
JonMnyConnect With a Mentor Commented:
if you put

    Me.TextBox1.Text = Page.User.Identity.Name
        Me.TextBox2.text = Environment.UserName

do they both have DATAWHSE\IUSR_DATAWHSE

0
 
weareitCommented:
If you want the currently logged in user you could do this:

Imports System.Windows.Forms
...
...
...
...
TextBox1.Text = System.Windows.Forms.SystemInformation.UserName

-saige-
0
 
SQL_SERVER_DBACommented:
Declare Function GetUserName Lib "advapi32.dll" Alias _
       "GetUserNameA" (ByVal lpBuffer As String, _
       ByRef nSize As Integer) As Integer

   Public Function GetUserName() As String
       Dim iReturn As Integer
       Dim userName As String
       userName = New String(CChar(" "), 50)
       iReturn = GetUserName(userName, 50)
       GetUserName = userName.Substring(0, userName.IndexOf(Chr(0)))
   End Function
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
JonMnyCommented:


text1.text =Page.User.Identity.Name
0
 
D-bassAuthor Commented:
I was able to get the  "TextBox1.Text = Page.User.Identity.Name" to compile but is not returning anything to the textbox1. Do I need to do any kind of conversion?
0
 
JonMnyCommented:
No in my asp.net it returns qa-ent\jonO

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
TextBox1.Text = Page.User.Identity.Name




    End Sub


you could try
        TextBox1.Text = My.User.Name


0
 
D-bassAuthor Commented:
Still does not return a value. In my aspx page I am able to return the local account name using the following:

TextBox1.Text = Request.LogonUserIdentity.Name

However, when I publish the page it still pulls the name from the local server. I guess this is an issue with how I have the connection set up?
0
 
weareitCommented:
You might have to embed some of your code into a page that loads on the client side...  This code does nothing but pulls the local login account, assigns it to a variable and then passes it back to the server as a variable...

-saige-
0
 
JonMnyCommented:
I think you need to make sure it's using impersionation on the server.

<system.web>
        <identity impersonate="true" />
    </system.web>
0
 
weareitCommented:
I was able to use:

Imports System
Partial Class _Default
      Inherits System.Web.UI.Page
      Protected Sub TextBox1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Load
            TextBox1.Text = My.User.Name
      End Sub
End Class

When I just made a one page project in VS2005.

-saige-
0
 
D-bassAuthor Commented:
weareit,

That code does work when i create a "new project" and form. But it does not work when I create a "new website" in VS2005 and create a web form. Do you know the syntax difference between the two?
0
 
weareitCommented:
In all honesty I would have to say that I do not know of any syntax differences between the two.  My initial response was for a VBAPP.  I'll dig a little depper.

-saige-
0
 
JonMnyCommented:

System.Web.UI.Page.User.Identity.Name
pulls the user ID of the current logged-in user,  whether the user's identity is established with ASP.NET login controls (and implicitly, ASP.NET membership) or with Integrated Windows authentication

I use this all the time in web pages, is it showing aspnet? when you run it on the server


see also
http://msdn2.microsoft.com/en-us/library/ms178344(vs.80).aspx


0
 
D-bassAuthor Commented:
I am able to pull the useridentity, but it always pulls the local user i.e adinistrator or Datawhse. Even after publishing the page , when I open the page from my local computer the local user (to the server) is displayed. here is thecode:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.TextBox11.Text = Me.Request.LogonUserIdentity.Name

TextBox11 is always "DATAWHSE\IUSR_DATAWHSE"

Any ideas? Again sorry for lapse of time, priorites changed and I now have some spare time to work on this isssue again.

Thanks!
D-bass
0
 
D-bassAuthor Commented:
the first line returns nothing
the secound returns "NETWORK SERVICE"
0
 
JonMnyCommented:
are you allowing anonymous requests? If so then  Page.User is blank and Environment.User would be network service.

when Impersonation is enabled ASP.NET will change the impersonation on the underlying thread to match of who's logged on.  For anonymous users this will be the IUSR_ account or if logged on the user who logged on.


0
 
D-bassAuthor Commented:
can you tell me how to disable anonymous requests so I can capture the active directory user name?
0
 
JonMnyCommented:
on iis right click on your web site, click on properties, select the directory security tab, click edit under Authentication and access control, uncheck  enable anonymous access
0
 
D-bassAuthor Commented:
That was the issue. Worked beautifully. Thank you so much!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.