Hi guru_sami
Thank you for your help so far. My errors have decreased considerably. Please could you help with the Csql class and Login method? My dataset is called HRdataset and my tableadapter is called Account_UserTableAdapter. I'm not quite sure how to reference them in the code? I've attached what I believe is true but could do with some help please.
Thank you/
This is the updated code:
using System;
using System.Data;
using System.Configuration;
using System.Linq;
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.Xml.Linq;
namespace SmartLearner
{
public class CCommonDB: CSql {public CCommonDB() : base() { }
public string AuthenticateUser(
System.Web.SessionState.HttpSessionState objSession, // Session Variable
System.Web.HttpResponse objResponse, // Response Variable
string email, // Login
string password, // Password
bool bPersist // Persist login
)
{
string url = String.Empty;
if(nLoginID != 0) // Success
{ // Log the user in
System.Web.Security.FormsAuthentication.SetAuthCookie(nLoginID.ToString(), bPersist);
// Set the session varaibles
objSession["loginID"] = nLoginID.ToString();
objSession["loginType"] = nLoginType.ToString();
// Set cookie information incase they made it persistant
System.Web.HttpCookie wrapperCookie = new System.Web.HttpCookie("wrapper");
wrapperCookie.Value = objSession["wrapper"].ToString();
wrapperCookie.Expires = DateTime.Now.AddDays(30);
System.Web.HttpCookie lgnTypeCookie = new System.Web.HttpCookie("loginType");
lgnTypeCookie.Value = objSession["loginType"].ToString();
lgnTypeCookie.Expires = DateTime.Now.AddDays(30);
// Add the cookie to the response
objResponse.Cookies.Add(wrapperCookie);
objResponse.Cookies.Add(lgnTypeCookie);
// If you are refering 1,2, for LoginID replace it in switch
switch(LoginType)
{
case 1: // Admin Login
url = "/Admin.aspx";
break;
case 2: // Staff Login
url = "/Staff.aspx";
break;
default:
url = "/Login.aspx";
break;
} //end switch
} //end if
return url;
}
}
/// <summary>
/// Verifies the login and password that were given
/// </summary>
/// <param name="email">the login</param>
/// <param name="password">the password</param>
/// <param name="nLoginID">returns the login id</param>
/// <param name="nLoginType">returns the login type</param>
public void Login(string email, string password, ref int nLoginID, ref int nLoginType)
{ ResetSql();
DataSet ds = new HRdataSet.xsd;
// Set our parameters
SqlParameter paramLogin = new
SqlParameter("@username", SqlDbType.VarChar, 100);
paramLogin.Value = email;
SqlParameter paramPassword = new SqlParameter("@password", SqlDbType.VarChar, 20);
paramPassword.Value = password;
Command.CommandType = CommandType.StoredProcedure;
Command.CommandText = "glbl_Login";
Command.Parameters.Add(paramLogin);
Command.Parameters.Add(paramPassword);
Adapter.TableMappings.Add("Table", "Login");
Adapter.SelectCommand = Command;
Adapter.Fill(ds);
if(ds.Tables.Count != 0)
{
DataRow row = ds.Tables[0].Rows[0];
// Get the login id and the login type
nLoginID = Convert.ToInt32(row["nLoginID"].ToString());
nLoginType = Convert.ToInt32(row["LoginType"].ToString());
}
else
{
nLoginID = 0;
nLoginType = 0;
}
)
}
}
abstract public class CSql
{
private SqlConnection sqlConnection; // Connection string
private SqlCommand sqlCommand; // Command
private SqlDataAdapter Account_UserTableAdapter; // Data Adapter
private DataSet HRdataSet; // Data Set
public CSql()
{
sqlConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
sqlCommand = new SqlCommand();
sqlDataAdapter = new Account_UserTableAdapter();
sqlDataSet = new HRdataSet();
sqlCommand.Connection = sqlConnection;
}
/// <summary>
/// Access to our sql command
/// </summary>
protected SqlCommand Command
{
get { return sqlCommand; } }
/// <summary>
/// Access to our data adapter
/// </summary>
protected SqlDataAdapter Account_UserTableAdapter
{
get { return sqlDataAdapter; } }
/// <summary>
/// Makes sure that everything is clear and ready for a new query
/// </summary>
protected void ResetSql()
{
if(sqlCommand != null)
{ sqlCommand = new SqlCommand();
sqlCommand.Connection = sqlConnection;
}
if(sqlDataAdapter != null)
sqlDataAdapter = new SqlDataAdapter();
if(sqlDataSet != null)
sqlDataSet = new DataSet(); }
/// <summary>
/// Runs our command and returns the dataset
/// </summary>
/// <returns>the data set</returns>
protected DataSet RunQuery()
{
sqlDataAdapter.SelectCommand = Command;
sqlConnection.Open();
sqlConnection.Close();
sqlDataAdapter.Fill(sqlDataSet);
return sqlDataSet; }
}
}
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159:





by: guru_samiPosted on 2009-08-19 at 16:12:41ID: 25138212
If you login successfully you will be returned to Default.aspx due to this statemente:
uthenticat ion.SetAut hCookie(nL oginID.ToS tring(), bPersist); pper"); ring(); inType"); String(); apperCooki e); nTypeCooki e);
--> return "/default.aspx";
And you won't even reach other statements even if they are syntactically correct.
What is LoginID / what is LoginType??
So I think you want to redirect user to specific page depending on theLoginTtype right?
If yes... try the code below:
string url = String.Empty;
if(nLoginID != 0) // Success
{ // Log the user in
System.Web.Security.FormsA
// Set the session varaibles
objSession["loginID"] = nLoginID.ToString();
objSession["loginType"] = nLoginType.ToString();
// Set cookie information incase they made it persistant
System.Web.HttpCookie wrapperCookie = new System.Web.HttpCookie("wra
wrapperCookie.Value = objSession["wrapper"].ToSt
wrapperCookie.Expires = DateTime.Now.AddDays(30);
System.Web.HttpCookie lgnTypeCookie = new System.Web.HttpCookie("log
lgnTypeCookie.Value = objSession["loginType"].To
lgnTypeCookie.Expires = DateTime.Now.AddDays(30);
// Add the cookie to the response
objResponse.Cookies.Add(wr
objResponse.Cookies.Add(lg
// If you are refering 1,2, for LoginID replace it in switch
switch(LoginType)
{
case 1: // Admin Login
url = "/Admin.aspx";
break;
case 2: // Staff Login
url = "/Staff.aspx";
break;
default:
url = "/default.aspx";
break;
} //end switch
} //end if
return url;
Set break points within the code and note whats happening on while you debug...