...

View Full Version : How to capture the logon username from another server



jennypretty
10-10-2007, 08:42 PM
Hello,

I am creating an asp form like this:

<html>
<title>Jenny Pretty</title)
<header>
</header>
<body>
<%
Response.Write Request.ServerVariables("username_field")
%>
<form action="jenny_action.asp" name="Jennyfrm" method="post")
<input type="text" size="15" maxlength="100" name="LastName" title="Last name" />,
<input type="text" size="15" maxlength="50" name="FirstName" title="First name" />
<input type="text" size="1" maxlength="1" name="MiddleInitial" title="Middle name" />
</form>


I placed this form under Intranet folder so that whenever a user open this form, it pops up a logon screen for Username/password.

I am trying to capture the logon username and store it in my database.

My form does not show any error but I don't see any username.

I am a newbie in ASP.
Can you please help me how to capture the logon username in details?

Thank you for reading!!!

Jenny.

:thumbsup:

angst
10-10-2007, 08:48 PM
something like this maybe?



<html>
<title>Jenny Pretty</title)
<header>
</header>
<body>
<%
Response.Write Request.Form("LastName")
%>
<form action="jenny_action.asp" name="Jennyfrm" method="post")
<input type="text" size="15" maxlength="100" name="LastName" title="Last name" />,
<input type="text" size="15" maxlength="50" name="FirstName" title="First name" />
<input type="text" size="1" maxlength="1" name="MiddleInitial" title="Middle name" />
</form>

Daemonspyre
10-10-2007, 09:19 PM
Couple of small typos and 1 missing element are holding you back:



<html>
<head>
<title>Jenny Pretty</title>
</head>
<body>
<% if request.form("LastName") <> "" then Response.Write("You entered: " & Request.Form("LastName")) %>
<form action="jenny_action.asp" name="Jennyfrm" method="post")
<input type="text" size="15" maxlength="100" name="LastName" title="Last name" />
<input type="text" size="15" maxlength="50" name="FirstName" title="First name" />
<input type="text" size="1" maxlength="1" name="MiddleInitial" title="Middle name" /><br /><br />
<input type="submit" name="B1" value="Log On" />
</form>

You were missing the SUBMIT button. Can't submit the form (with a mouse) without one. You can, however, always use the ENTER key.

To write this information to a database, then all you need to do is:



<%
if request.form("FirstName") <> "" AND request.form("LastName") <> "" then
'
Set Conn = Server.CreateObject("ADODB.Connection")
'Provide Connection to your database below
Conn.open "..."
'
strSQL = "INSERT INTO your_table (FirstName,MiddleInitial,LastName) VALUES ("
'
strSQL = strSQL & "'" & replace(request.form("FirstName"),"'","\'") & "',"
'
if request.form("MiddleInitial") <> "" then
strSQL = strSQL & "'" & request.form("MiddleInitial") & "',"
else
strSQL = strSQL & "NULL,"
end if
'
strSQL = strSQL & "'" & replace(request.form("LastName"),"'","\'") & "');"
'
'Comment (place a single quote in front of the line) the following few lines to get this to write to your database.
'The code below is standard error checking to make sure you are using the correct SQL statement.
'
response.write strSQL
response.flush
schtopp
'
Conn.Execute strSQL, lngRecs, adCmdText + adExecuteNoRecords
strSQL = ""
Conn.Close
Set Conn = Nothing
'
response.redirect("successful_logon.asp")
else
response.write("You have not entered all the required information. Please try again.<br />" & vbCrLf)
end if
%>
<html>
<head>
<title>Jenny Pretty</title>
</head>
<body>
<form action="jenny_action.asp" name="Jennyfrm" method="post")
<input type="text" size="15" maxlength="100" name="LastName" title="Last name" />
<input type="text" size="15" maxlength="50" name="FirstName" title="First name" />
<input type="text" size="1" maxlength="1" name="MiddleInitial" title="Middle name" /><br /><br />
<input type="submit" name="B1" value="Log On" />
</form>

jennypretty
10-10-2007, 09:42 PM
I think my question is not clear.
I am trying to capture the logon username from the 2nd server.
For example, I store my file jenny.asp on server A and place this file under Intranet folder. Whenever this file is opened, it pops up a logon screen which is placed on server B.

Maybe I gave a wrong sample.

Here is my sample page:


<html>
<title>Jenny Pretty</title)
<header>
</header>
<body>
<%
Response.Write Request.ServerVariables("username_field")
%>
</body>
</html>


It is supposed to print out the logon username on screen. But I got blank page.

Please advice.

Thanks!!!

angst
10-10-2007, 09:47 PM
ah, i see.

maybe a cookie would work best for this.

http://www.w3schools.com/asp/asp_cookies.asp

Spudhead
10-11-2007, 02:39 PM
You say this is on your intranet, and "it pops up a logon screen for Username/password" - does this popup window say something like "Authentication Required" in the title bar?

If so, you need Request.ServerVariables("LOGON_USER") instead of Request.ServerVariables("username_field")

jennypretty
10-11-2007, 02:41 PM
I think cookies are not working on my sample. I want to create a hidden field to capture and store the logon username from the server B on my db.
I know the Field Name of the logon username.
But when I tried that, it shows nothing on screen.


Response.Write Request.ServerVariables("username_field")

Please advice.
Thanks.

jennypretty
10-11-2007, 02:44 PM
It is not about windows authentication so it does not have that. It is about Intranet logon screen that requires all files that are placed under Intranet must logon for security purpose.

I know the Field Name of the logon username.
But when I tried that, it shows nothing on screen.

Thanks.

Spudhead
10-11-2007, 03:07 PM
Ok. The second bit of code you posted - the simple page that just writes out Request.ServerVariables("username_field"):

There is nothing in the Request.ServerVariables collection called "username_field". (http://www.aspcode.net/List-of-RequestServerVariables.aspx) That's why you're not seeing anything written to the screen.

So this page is in an "Intranet" folder on your server. And when people try to get to pages on this server, they get a popup box, that asks them for a username and password. Not a HTML form, this is a popup window. Right?

This sounds a LOT like IIS authentication. And if it is, you need to use Request.ServerVariables("LOGON_USER").

If you're absolutely 100% sure that your IIS server is allowing anonymous access to your Intranet folder - which it doesn't sound like - and that security is managed by the ASP application itself, then somewhere there is a form. A HTML form.

You say you "know the Field Name of the logon username": you mean you know the name of the HTML input box in that form, that people are typing their username into? Show me. Post that form.

jennypretty
10-11-2007, 03:44 PM
The second bit of code you posted - the simple page that just writes out Request.ServerVariables("username_field"):

How do I change the code to print out the value?

So this page is in an "Intranet" folder on your server. And when people try to get to pages on this server, they get a popup box, that asks them for a username and password. Not a HTML form, this is a popup window. Right?

No, this is an HTML form. (I have a Username Field Name)


<form name="login" method="post">
<input type=hidden name=target value="authenticate.do">
<br><b>Username</b>:<br><input autocomplete="OFF" type="text" name="USERNAME" size="27"><br>
<b>Password</b>:<br><input autocomplete="OFF" type="password" name="PASSWORD" size="27"><br>
<input style="width: 80px;" type="button" id="button" value="Login">


For example:
For a new user to post on this forum, when he want to post a new topic, it points him to this login page: http://www.codingforums.com/newthread.php? do=newthread&f=8 to type in his username/password. I want to capture the username and store it in my db.

What do I need to know about their server in order to do capture the "User name" content from this screen before it passes to my page?

Thanks!!!

Spudhead
10-11-2007, 05:40 PM
What do I need to know about their server in order to do capture the "User name" content from this screen before it passes to my page?

Try this:

response.write request.form("USERNAME")

But that login form is calling a page called "authenticate.do" - ideally you need to see what that page is doing with the info it receives.

jennypretty
10-11-2007, 06:57 PM
it is kind of hard to get the logon username from different server, right?
It looks like impossible to do.
Thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum