I have a simple login screen that now has to receive its parameters from another web site. I am not sure what we have to do. The other web site, will get the user id and password. the person there is asking me, does he just redirect user to
this is the codes: First is Login.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="Reports.Login" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " xmlns=" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width:100%;">
<tr>
<td width="60%">
</td>
<td width="20%">
</td>
<td width="20%">
</td>
</tr>
<tr>
<td>
</td>
<td style="text-align: right">
</td>
<td>
<asp:Label ID="lblMessage" runat="server" ForeColor="Red"
style="font-family: Arial, Helvetica, sans-serif; font-size: small"></asp:Label>
</td>
</tr>
<tr>
<td>
</td>
<td style="text-align: right">
<asp:Label ID="Label1" runat="server"
style="font-family: Arial, Helvetica, sans-serif; font-size: small;"
Text="UserName : "></asp:Label>
</td>
<td>
<asp:TextBox ID="txtUserName" runat="server"
style="font-family: Arial, Helvetica, sans-serif" Text="User"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td style="text-align: right">
<asp:Label ID="Label2" runat="server"
style="text-align: right; font-family: Arial, Helvetica, sans-serif; font-size: small;"
Text="Password : "></asp:Label>
</td>
<td>
<asp:TextBox ID="txtPassword" runat="server"
style="font-family: Arial, Helvetica, sans-serif" Text="test" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
<asp:Button ID="btnLogin" runat="server" onclick="btnLogin_Click"
style="font-family: Arial, Helvetica, sans-serif" Text="Login" />
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
<html
Then there is Login.aspx.cs, basically at the statement response.redirect it will then display the screen we want
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Xml;
using Reports.Helpers;
namespace Reports
{
public partial class Login : System.Web.UI.Page
{
const string XML_CONFIG_FILE = "reports.xml";
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ClearSession();
}
// Compilation Directive
// This will by-pass the authentication when DEV flag is added to Conditional Compilation Symbols
// If not, it will ask for login as usual
#if DEV
txtPassword.Text = " ";
btnLogin_Click(null, null);
#endif
}
private void ClearSession()
{
// Clear all Session data
Session.Clear();
}
protected void btnLogin_Click(object sender, EventArgs e)
{
ClearSession();
lblMessage.Text = "";
// Perform Login based on the entered UserName and Password
string sql = "Select * from Users where UserName = '" + txtUserName.Text.Replace("'", "") + "' and Password = '" + txtPassword.Text.Replace("'", "") + "'";
DataSet ds = Lib.GetResults(sql, ConnectionHelper.GetSecurityDatabaseConnection());
if (ds != null)
{
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count == 1)
{
Session["UserName"] = txtUserName.Text.Trim();
Response.Redirect("DashBoard.aspx");
}
else
{
lblMessage.Text = "Invalid UserName/Password.";
}
}
else
{
lblMessage.Text = "Invalid UserName/Password.";
}
}
else
{
lblMessage.Text = "Invalid UserName/Password.";
}
}
}
}
this is the codes: First is Login.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="Reports.Login" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " xmlns=" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width:100%;">
<tr>
<td width="60%">
</td>
<td width="20%">
</td>
<td width="20%">
</td>
</tr>
<tr>
<td>
</td>
<td style="text-align: right">
</td>
<td>
<asp:Label ID="lblMessage" runat="server" ForeColor="Red"
style="font-family: Arial, Helvetica, sans-serif; font-size: small"></asp:Label>
</td>
</tr>
<tr>
<td>
</td>
<td style="text-align: right">
<asp:Label ID="Label1" runat="server"
style="font-family: Arial, Helvetica, sans-serif; font-size: small;"
Text="UserName : "></asp:Label>
</td>
<td>
<asp:TextBox ID="txtUserName" runat="server"
style="font-family: Arial, Helvetica, sans-serif" Text="User"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td style="text-align: right">
<asp:Label ID="Label2" runat="server"
style="text-align: right; font-family: Arial, Helvetica, sans-serif; font-size: small;"
Text="Password : "></asp:Label>
</td>
<td>
<asp:TextBox ID="txtPassword" runat="server"
style="font-family: Arial, Helvetica, sans-serif" Text="test" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
<asp:Button ID="btnLogin" runat="server" onclick="btnLogin_Click"
style="font-family: Arial, Helvetica, sans-serif" Text="Login" />
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
<html
Then there is Login.aspx.cs, basically at the statement response.redirect it will then display the screen we want
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Xml;
using Reports.Helpers;
namespace Reports
{
public partial class Login : System.Web.UI.Page
{
const string XML_CONFIG_FILE = "reports.xml";
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ClearSession();
}
// Compilation Directive
// This will by-pass the authentication when DEV flag is added to Conditional Compilation Symbols
// If not, it will ask for login as usual
#if DEV
txtPassword.Text = " ";
btnLogin_Click(null, null);
#endif
}
private void ClearSession()
{
// Clear all Session data
Session.Clear();
}
protected void btnLogin_Click(object sender, EventArgs e)
{
ClearSession();
lblMessage.Text = "";
// Perform Login based on the entered UserName and Password
string sql = "Select * from Users where UserName = '" + txtUserName.Text.Replace("'", "") + "' and Password = '" + txtPassword.Text.Replace("'", "") + "'";
DataSet ds = Lib.GetResults(sql, ConnectionHelper.GetSecurityDatabaseConnection());
if (ds != null)
{
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count == 1)
{
Session["UserName"] = txtUserName.Text.Trim();
Response.Redirect("DashBoard.aspx");
}
else
{
lblMessage.Text = "Invalid UserName/Password.";
}
}
else
{
lblMessage.Text = "Invalid UserName/Password.";
}
}
else
{
lblMessage.Text = "Invalid UserName/Password.";
}
}
}
}