
July 30th, 2002, 12:52 PM
|
|
Contributing User
|
|
Join Date: Dec 2002
Posts: 14,575
  
Time spent in forums: < 1 sec
Reputation Power: 22
|
|
|
Capturing Login Info.
<i><b>Originally posted by : Tim (timothy.farrell@compuware.com)</b></i><br />Can anyone tell me how I can capture my users login information to post to a subsequent page following login? For example when a user attempts to access my app, they are prompted to login. Once successful, I want their name and employee number to post to the application start page. <br /><br />I am using forms based authentication that references a SQL2000 db to verify credentials. <br /><br />Here is the code of the login page: <br /><font color="green"> <br /><%@ Import NameSpace="System.Data.SqlClient"%> <br /><%@ Import NameSpace="System.Data"%> <br /><%@ Page Language="vb"%> <br /><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <br /><html> <br /> <head> <br /> <title>Login</title> <br /> <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0> <br /> <meta name="CODE_LANGUAGE" content="Visual Basic 7.0> <br /> <meta name="vs_defaultClientScript" content="JavaScript"> <br /> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> <br /> </head> <br /> <body leftmargin="0" topmargin="30"> <br /> <script runat="server" language="vb"> <br /> Protected Sub Login_OnClick(Sender as Object, E As EventArgs) <br /> Dim SqlStmt As String = "Select Count(*) FROM Employee WHERE UID='" & _ <br /> UID.Text.Trim() & "' " & _ <br /> "AND Pwd = '" & _ <br /> Pwd.Text.Trim() & "'" <br /> Dim con As SqlConnection = New SqlConnection("server=ntphoenix;database=plan;uid=***;pwd=***") <br /> Dim cmd As SqlCommand = New SqlCommand(SqlStmt, con) <br /> Dim reader As SqlDataReader = Nothing <br /> <br /> con.open() <br /> reader = cmd.ExecuteReader() <br /> While reader.Read() <br /> If Int32.Parse(reader(0).ToString()) >= 1 Then <br /> FormsAuthentication.RedirectFromLoginPage(UID.Text ,PersistCookie.Checked) <br /> Else <br /> ErrorMsg.Text = "<p><b><font color='#cc3300'>User not found or bad credentials - try again!</font></b></p>" <br /> End If <br /> End While <br /> End Sub <br /> <br /> Protected Sub Signout_Onclick(Sender As Object, E As EventArgs) <br /> FormsAuthentication.Signout() <br /> HttpContext.Current.Response.Redirect("login.aspx") <br /> End Sub <br /> </script> <br /> <form runat="server"> <br /> <!--#include file="Styles.css" --> <br /> <div align="center"> <br /> <table cellpadding="0" cellspacing="0" border="0" bordercolor="Gainsboro" bordercolordark="DarkBlue"> <br /> <tr> <br /> <td colspan="2" width="400" align="middle"><img src="images/login.gif"></td> <br /> </tr> <br /> <tr> <br /> <td colspan="2"> </td> <br /> </tr> <br /> <tr class="tabletext" bgcolor="AliceBlue"> <br /> <td>Employee UID:</td> <br /> <td><asp:TextBox id="UID" runat="server"></asp:TextBox></td> <br /> </tr> <br /> <tr class="tabletext" bgcolor="AliceBlue"> <br /> <td>Password:</td> <br /> <td><asp:TextBox id="Pwd" runat="server" TextMode="Password"></asp:TextBox></td> <br /> </tr> <br /> <tr> <br /> <td colspan="2"> </td> <br /> </tr> <br /> <tr class="tabletext"> <br /> <td>Remember Me:</td> <br /> <td><asp:CheckBox Runat="server" ID="PersistCookie" /> <br /> Check here to save your credentials to your computer.</td> <br /> </tr> <br /> <tr> <br /> <td colspan="2"> </td> <br /> </tr> <br /> <tr> <br /> <td colspan="2"><asp:Label Runat="server" ID="ErrorMsg" /></td> <br /> </tr> <br /> <tr> <br /> <td colspan="2"><asp:Button Text="Login" OnClick="Login_OnClick" RunAt="server" ID="Button1" /><asp:Button Text="Sign-Out" OnClick="Signout_OnClick" RunAt="server" ID="Signout" /></td> <br /> </tr> <br /> <tr> <br /> <td colspan="2"> </td> <br /> </tr> <br /> <tr class="tabletext" bgcolor="PapayaWhip"> <br /> <td colspan="2">You must be registered to use this system. If you are not yet <br /> registered, please go <a href="register.aspx">here</a>.</td> <br /> </tr> <br /> </table> <br /> </div> <br /> </form> <br /> </body> <br /></html> <br /></font> <br />
|