Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Regular Coder
    Join Date
    Nov 2005
    Posts
    225
    Thanks
    2
    Thanked 0 Times in 0 Posts

    How to capture the logon username from another server

    Hello,

    I am creating an asp form like this:
    Code:
    <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.


  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    something like this maybe?

    PHP Code:
    <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

  • #3
    Regular Coder
    Join Date
    Mar 2007
    Posts
    505
    Thanks
    1
    Thanked 19 Times in 19 Posts
    Couple of small typos and 1 missing element are holding you back:

    Code:
    <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:

    Code:
    <%
    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>
    To say my fate is not tied to your fate is like saying, 'Your end of the boat is sinking.' -- Hugh Downs
    Please, if you found my post helpful, pay it forward. Go and help someone else today.

  • #4
    Regular Coder
    Join Date
    Nov 2005
    Posts
    225
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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:
    Code:
    <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!!!

  • #5
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    ah, i see.

    maybe a cookie would work best for this.

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

  • #6
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    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")

  • #7
    Regular Coder
    Join Date
    Nov 2005
    Posts
    225
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.

    Code:
    Response.Write Request.ServerVariables("username_field")
    Please advice.
    Thanks.

  • #8
    Regular Coder
    Join Date
    Nov 2005
    Posts
    225
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.

  • #9
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    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". 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.

  • #10
    Regular Coder
    Join Date
    Nov 2005
    Posts
    225
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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)
    Code:
       <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!!!

  • #11
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Quote Originally Posted by jennypretty
    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.

  • #12
    Regular Coder
    Join Date
    Nov 2005
    Posts
    225
    Thanks
    2
    Thanked 0 Times in 0 Posts
    it is kind of hard to get the logon username from different server, right?
    It looks like impossible to do.
    Thanks.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •