but I have My own authenticate methods and I searched a lot so I think the Issue isn't related in my code
private bool GetMemberAuthenticate(string Username, string Pwd)
{
bool RetVal = false;
RetVal=Convert.ToBoolean(MyDALBase.ExecuteScaler(System.Data.CommandType.StoredProcedure, "GetMemberByUsernameandPwd", new SqlParameter[]{
new SqlParameter("@Username",Username),
new SqlParameter("@Pwd",Pwd)
}));
return RetVal;
}
private string GetMemberRoleByID(string Username)
{
SqlDataReader dr = MyDALBase.ExecuteReader(System.Data.CommandType.StoredProcedure, "GetRolesByUsername", new SqlParameter[]{
new SqlParameter("@Username",Username)
});
string RetVal = "NA";
if (dr.Read())
{
RetVal = dr["Roles"].ToString();
}
return RetVal;
}
and mybe it's a bug i asp.net. because the same code works in a host but not in other host and it works in my local computer.
I don't want to made big change in my codes.
I dont use built in login control and asp.net membership tables. I have my own
and that work perfectly in local. and in host It remember user for a variable time for example 40 minutes. I can see cookie by firefox and its expiration set to one month later as I expect. but for a unknown reason after a while asp.net cant Identify the cookie although it's exist. someone in a forum said that's a bug in asp.net and his solution was *get cookie in request *make a new cookie again *and pass it to client with response I cant get his concept. does someone undrstand his concept? I don't know when, where I must make a new cookie? In global.asax? I asked him in private message but I'm not sure he come to that forum again so please help me do his solution. based on his solution I change my global.asax code to this but I know it's wrong
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
HttpCookie authCookiee = Context.Request.Cookies[FormsAuthentication.FormsCookieName.ToString()];
HttpCookie test = new HttpCookie("test", authCookiee.ToString());
Response.Cookies.Add(test);
if (test!=null)
{
FormsAuthenticationTicket MyTickett;
MyTickett = FormsAuthentication.Decrypt(authCookiee.Value);
FormsIdentity MyIdentity = new FormsIdentity(MyTickett);
GenericPrincipal MyPrincipal = new GenericPrincipal(MyIdentity, MyTickett.UserData.Split(new char[] { ',' }));
Context.User = MyPrincipal;
}
}
Bahare Feizi
Member
30 Points
39 Posts
Rmebmer Me doesn work in host
Jan 29, 2013 04:37 PM|LINK
Hi every one
Remember Me works fine in local but not in server
.
what reasons could there be?
this is in web.config
<system.web> <sessionState mode="InProc"></sessionState> <httpRuntime requestValidationMode="2.0" maxRequestLength="20951"/> <customErrors mode="Off"></customErrors> <authentication mode="Forms"> <forms name="AuthCookiee" slidingExpiration="true" timeout="43200" loginUrl="Default.aspx" defaultUrl="~/"></forms> </authentication>this is code in global.asax
protected void Application_AuthenticateRequest(object sender, EventArgs e) { HttpCookie authCookiee = Context.Request.Cookies[FormsAuthentication.FormsCookieName.ToString()]; if (authCookiee != null) { FormsAuthenticationTicket MyTickett; MyTickett = FormsAuthentication.Decrypt(authCookiee.Value); FormsIdentity MyIdentity = new FormsIdentity(MyTickett); GenericPrincipal MyPrincipal = new GenericPrincipal(MyIdentity, MyTickett.UserData.Split(new char[] { ',' })); Context.User = MyPrincipal; } }This is in login button click event
protected void btn_login_Click(object sender, EventArgs e) { if (!Page.User.Identity.IsAuthenticated) { if (GetMemberAuthenticate(txt_uname.Text, FormsAuthentication.HashPasswordForStoringInConfigFile(txt_pass.Text, "MD5"))) { string role = GetMemberRoleByID(txt_uname.Text); DateTime expiration; if (chk_rememberme.Checked) { expiration = DateTime.Now.AddMonths(1); } else { expiration = DateTime.Now.AddMinutes(10); } FormsAuthenticationTicket AuthTickett = new FormsAuthenticationTicket(1, txt_uname.Text, DateTime.Now, expiration,true, role); string encryptedTicket = FormsAuthentication.Encrypt(AuthTickett); HttpCookie AuthCookiee = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); AuthCookiee.Expires = expiration; Response.Cookies.Add(AuthCookiee);Thanks a lot
oned_gk
All-Star
31013 Points
6350 Posts
Re: Rmebmer Me doesn work in host
Jan 30, 2013 12:24 AM|LINK
try use
Bahare Feizi
Member
30 Points
39 Posts
Re: Rmebmer Me doesn work in host
Jan 30, 2013 09:49 AM|LINK
wrongly I marked as answer
Bahare Feizi
Member
30 Points
39 Posts
Re: Rmebmer Me doesn work in host
Jan 30, 2013 10:03 AM|LINK
but I have My own authenticate methods and I searched a lot so I think the Issue isn't related in my code
private bool GetMemberAuthenticate(string Username, string Pwd) { bool RetVal = false; RetVal=Convert.ToBoolean(MyDALBase.ExecuteScaler(System.Data.CommandType.StoredProcedure, "GetMemberByUsernameandPwd", new SqlParameter[]{ new SqlParameter("@Username",Username), new SqlParameter("@Pwd",Pwd) })); return RetVal; } private string GetMemberRoleByID(string Username) { SqlDataReader dr = MyDALBase.ExecuteReader(System.Data.CommandType.StoredProcedure, "GetRolesByUsername", new SqlParameter[]{ new SqlParameter("@Username",Username) }); string RetVal = "NA"; if (dr.Read()) { RetVal = dr["Roles"].ToString(); } return RetVal; }and mybe it's a bug i asp.net. because the same code works in a host but not in other host and it works in my local computer.
I don't want to made big change in my codes.
I dont use built in login control and asp.net membership tables. I have my own
and that work perfectly in local.
and in host It remember user for a variable time for example 40 minutes.
I can see cookie by firefox and its expiration set to one month later as I expect.
but for a unknown reason after a while asp.net cant Identify the cookie although it's exist.
someone in a forum said that's a bug in asp.net and his solution was
*get cookie in request
*make a new cookie again
*and pass it to client with response I cant get his concept.
does someone undrstand his concept?
I don't know when, where I must make a new cookie?
In global.asax?
I asked him in private message but I'm not sure he come to that forum again
so please help me do his solution.
based on his solution I change my global.asax code to this but I know it's wrong
protected void Application_AuthenticateRequest(object sender, EventArgs e) { HttpCookie authCookiee = Context.Request.Cookies[FormsAuthentication.FormsCookieName.ToString()]; HttpCookie test = new HttpCookie("test", authCookiee.ToString()); Response.Cookies.Add(test); if (test!=null) { FormsAuthenticationTicket MyTickett; MyTickett = FormsAuthentication.Decrypt(authCookiee.Value); FormsIdentity MyIdentity = new FormsIdentity(MyTickett); GenericPrincipal MyPrincipal = new GenericPrincipal(MyIdentity, MyTickett.UserData.Split(new char[] { ',' })); Context.User = MyPrincipal; } }Bahare Feizi
Member
30 Points
39 Posts
Re: Rmebmer Me doesn work in host
Jan 31, 2013 06:23 AM|LINK
Hi,
I set machineKey in web.config and the problem solved.
hope this help somone else