Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trying to collect UserID

Status
Not open for further replies.

mayerl4

MIS
Joined
Nov 9, 2010
Messages
2
Location
US
Morning,


I've been scouring the forumsa and tutorials and I think I'm close. I'm trying to collect the username ofthe user connecting to the webapage (this is an intranet app) and submit it via a sql statement. My confusion is where you put what. On the default.aspx.vb I have a proteced sub page load and I have this code in it:

Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' Get the Logged on user
        ' Make sure Anonymous is not checked in IIS Manager
        ' otherwise this may be empty
        Dim strLogonUsr As String
        strLogonUsr = Request.ServerVariables("LOGON_USER")
        ' Create new parameters for the SqlCommand object and
        ' initialize them to the field values.
        ' Create the parameter for the logon user
        myCommand.Parameters.Add(New SqlParameter("@Logon_User", _SqlDbType.VarChar, 50))
        ' Assign the value
        myCommand.Parameters("@Logon_User").Value = strLogonUsr
        ' Create the parameter for the time
        myCommand.Connection.Open()

    End Sub

Then on the default.aspx I have some more code that tells how to connect to sql. The problem is that the logon_user id is never being populated to put into the statement.

The IIS server is set to windows authenticated. If anyone can help I would really appreciate it.

Thanks

Laura
 
Have a look at the value of User.Identity.Name instead.

However I suspect that it's probably more likely that your web.config is not set up to use Windows authentication, or that it is not set properly in IIS.

Mark,

Darlington Web Design[tab]|[tab]Experts, Information, Ideas & Knowledge[tab]|[tab]ASP.NET Tips & Tricks
 
Thanks Mark,

The authentication is set to windows and I unchecked anonymous access and checked integrated windows on the virtual directory.

So instead of strLogonUsr = Request.ServerVariables("LOGON_USER")

change that to strLogonUsr = user.identity.name instead?

Thanks

Laura
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top