Help needed getting current user via ASP

Soldato
Joined
11 Feb 2004
Posts
4,532
Location
Surrey, UK
I've created a web form which simply mails form data to recipients. However, I want to include the logged on users name.
This code should do it:string strName = HttpContext.Current.User.Identity.Name.ToString();

However, how do I include it in the code below? I need to add it to the line highlighted in yellow. The other lines include values pulled from the web form.

Dim myCDONTSMail
Dim strFrom
Dim strTo
Dim strSubject
Dim strMessage

strFrom=request.form("txtFrom")
strTo=request.form("txtTo")
strSubject = request.form("txtSubject")
strBody=""
strBody=strBody + "Request Name=" + request.form("reqName") + chr(10)
strBody=strBody + "Business Owners=" + request.form("") + chr(10)
strBody=strBody + "Request Owners=" + request.form("reqOwner") + chr(10)
 
Code:
Dim myCDONTSMail
Dim strFrom
Dim strTo
Dim strSubject
Dim strMessage
[i]Dim strName As String = HttpContext.Current.User.Identity.Name.ToString();[/i]

strFrom=request.form("txtFrom")
strTo=request.form("txtTo")
strSubject = request.form("txtSubject")
strBody=""
strBody=strBody + "Request Name=" + request.form("reqName") + chr(10)
strBody=strBody + "Business Owners=" + [i]strName[/i] + chr(10)
strBody=strBody + "Request Owners=" + request.form("reqOwner") + chr(10)
 
I am just wondering if you mean ASP or ASP.Net

the HttpContext.Current.... is in .Net
but the
Dim myCDONTSMail is classic ASP.


You can use
Request.ServerVariables("AUTH_USER")
OR
Request.ServerVariables("LOGON_USER")

Depending on how the server is set up.

Code:
Dim myCDONTSMail
Dim strFrom
Dim strTo
Dim strSubject
Dim strMessage
Dim strName

strName = Request.ServerVariables("LOGON_USER")

strFrom=request.form("txtFrom")
strTo=request.form("txtTo")
strSubject = request.form("txtSubject")
strBody=""
strBody=strBody + "Request Name=" + request.form("reqName") + chr(10)
strBody=strBody + "Business Owners=" + strName + chr(10)
strBody=strBody + "Request Owners=" + request.form("reqOwner") + chr(10)
 
Last edited:
You're right - it's classic ASP, my research into finding a solution failed!
I've created an HTML form, on submit, the form data is passed to an ASP page which processed and compiles the email.
I'm guessing I should add the variable to the web form field? Sorry - I'm a bit lost in all this but its expected of me! :)
 
You can add a field to the form and get the user to fill it in, which is probably you best bet as most websites are set the anonymous login so my code won't work either.

You could try my code and see though, or just

response.write(Request.ServerVariables("LOGON_USER"))

to see what it gives you.
 
You're right Simon, that will only give you the logged in ASP user - which will more often than not be 'IUSR_<machinename>'

Domo - if the system you have already has the ability to let user log in there will most likely be something in a session object/cookie which uniquely identifies them which you can use to query the database. Have a check of the code which processes user logins - that should give you a few clues.
 
Thanks for the advice guys. I'll post back when I've found a way to get this information. :)
 
Back
Top Bottom