我想让用户注册后登录。我的问题是用户注册并输入详细信息后我想让他自动登录。但是当我让用户登录代码时,登录状态和登录名没有显示任何内容即,用户尚未登录。
我的用户登录代码如下:
subl.LoadByLogin(ds, txtUserName.Text.Trim(), txtPassword.Text.Trim());
// bool rememberUserName = LoginUser.RememberMeSet;
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
SessionContext.SystemUser = WebHelper.Cast(ds.Tables[0].Rows[0]["SystemUser"], 0);
SessionContext.SystemUserX = ds.Tables[0].Rows[0]["FirstName"] + " " + ds.Tables[0].Rows[0]["LastName"];
SessionContext.SuperAdministrator = WebHelper.Cast(ds.Tables[0].Rows[0]["IsSuperAdmin"], false);
SessionContext.SiteAdministrator = WebHelper.Cast(ds.Tables[0].Rows[0]["IsSiteAdmin"], false);
SessionContext.IsTravelAgent = WebHelper.Cast(ds.Tables[0].Rows[0]["IsTravelAgent"], false);
SessionContext.TravelAgentID = WebHelper.Cast(ds.Tables[0].Rows[0]["TravelAgentID"], 0);
SessionContext.IsMember = WebHelper.Cast(ds.Tables[0].Rows[0]["IsMember"], false);
SessionContext.PropertyID = WebHelper.Cast(ds.Tables[0].Rows[0]["PropertyID"], 0);
SessionContext.MemberID = WebHelper.Cast(ds.Tables[0].Rows[0]["MemberID"], 0);
SessionContext.RegID = WebHelper.Cast(ds.Tables[0].Rows[0]["RegID"], 0);
SessionContext.Site = WebHelper.Cast(ds.Tables[0].Rows[0]["Site"], 0);
// SessionContext.Reseller = ds.Tables[0].Rows[0]["PropertyName"].ToString();
if (SessionContext.SuperAdministrator)
{
// SessionContext.SiteAdministrator = true;
}
// SessionContext.IsPublisher = WebHelper.Cast(ds.Tables[0].Rows[0]["IsPublisher"], false);
//Initialize FormsAuthentications
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, SessionContext.SystemUserX, DateTime.Now, DateTime.Now.AddMinutes(50), false, "Sparrow", FormsAuthentication.FormsCookiePath);
string hashCookies = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashCookies);
Response.Cookies.Add(cookie);