Re: authentication ticket expiring too soon
- From: bmjnine@xxxxxxxxxxx
- Date: 28 Sep 2006 17:30:01 -0700
Just curious -- what is it that indicates the cookies are not being
properly set?
I am using the following code to set the ticket:
(signin.aspx)
------------------
void Page_Load(Object s, EventArgs e) {
if (IsPostBack) {
int signinResult =
Authenticator.SignIn(TextBox_Email.Text,TextBox_Password.Text);
if (signinResult == 1)
FormsAuthentication.RedirectFromLoginPage(Authenticator.UserID, false);
else
Label_Error.Text = "That email/password combination is
invalid. Please try again.";
}
}
}
(Authenticator.cs)
------------------------
public class Authenticator
{
public Authenticator()
{
}
public static HttpCookie CookieObj
{
get
{
if (HttpContext.Current.Request.Cookies["UserInfo"] == null)
return new HttpCookie("UserInfo");
else
return HttpContext.Current.Request.Cookies["UserInfo"];
}
set
{
System.Web.HttpContext.Current.Response.Cookies.Add(value);
}
}
public static int SignIn(string email, string pw)
{
HttpCookie tmpCookieObj = new HttpCookie("UserInfo");
string sql = "SELECT FirstName, LastName, UserID FROM Users WHERE
EMail = '" + email.Trim() + "' " + "AND Password = '" + pw.Trim() +
"'";
using (OleDbConnection connectionObj = new
OleDbConnection(myConnectionString))
{
OleDbCommand Cmd = new OleDbCommand(sql,connectionObj);
connectionObj.Open();
OleDbDataReader DReader = Cmd.ExecuteReader();
if (DReader.Read())
{
string FirstName = DReader.GetString(0);
string LastName = DReader.GetString(1);
string UserID = DReader.GetInt32(2).ToString();
DReader.Close();
tmpCookieObj.Values.Add("FirstName", FirstName);
tmpCookieObj.Values.Add("LastName", LastName);
tmpCookieObj.Values.Add("UserID", UserID);
tmpCookieObj.Expires = DateTime.Now.AddDays(3);
CookieObj = tmpCookieObj;
return 1;
}
else
{
DReader.Close();
connectionObj.Close();
return -1;
}
}
}
public static string UserID
{
get
{
if (CookieObj["UserID"] != null)
return CookieObj["UserID"];
else
return String.Empty;
}
}
}
I should also now note the other cookie that appears on the test page
(previously omitted):
Name: UserInfo
Value: FirstName=Joe&LastName=Smith&UserID=1
Domain:
Path: /
HasKeys: True
Expires: 1/1/0001 12:00:00 AM
Thanks,
Alyssa
Gaurav Vaish (www.EduJiniOnline.com) wrote:
Name: UserID
Expires: 1/1/0001 12:00:00 AM
Name: ASP.NET_SessionId
Expires: 1/1/0001 12:00:00 AM
The cookies are not being properly set.
Neither for ASP.Net_SessionId, nor for UserID.
Just check how you are generating and setting the FormsAuthenticationTicket?
--
Happy Hacking,
Gaurav Vaish | http://www.mastergaurav.com
http://www.edujinionline.com
http://articles.edujinionline.com/webservices
-------------------
.
- Follow-Ups:
- Re: authentication ticket expiring too soon
- From: Gaurav Vaish \(www.EduJiniOnline.com\)
- Re: authentication ticket expiring too soon
- Prev by Date: Re: Login failed for user '(null)'.
- Next by Date: Re: ASP.NET and directory security
- Previous by thread: Re: Login failed for user '(null)'.
- Next by thread: Re: authentication ticket expiring too soon
- Index(es):
Relevant Pages
|