private void createCookie() { try { bool createPersistentCookie = true; string username = txtemailID.Text; string pass = txtpwd.Text; FormsAuthentication.Initialize(); ////HttpCookie cookie = new HttpCookie("UserName"); ////cookie.Value = username; ////cookie.Expires = DateTime.Now.AddDays(1); //////cookie["username"] = username; ////Response.Cookies.Add(cookie); ////string ckValue = Request.Cookies["UserName"].Value; HttpCookie cookie = FormsAuthentication.GetAuthCookie(username, createPersistentCookie); var time = DateTime.Now.AddDays(1); cookie.Expires = time; var userData = username; var cookieVal = FormsAuthentication.Decrypt(cookie.Value); FormsAuthenticationTicket aticket = new FormsAuthenticationTicket(cookieVal.Version, cookieVal.Name, cookieVal.IssueDate, time, true, userData); cookie.Value = FormsAuthentication.Encrypt(aticket); HttpContext.Current.Response.Cookies.Add(cookie); //HttpContext.Current.Response.Cookies.Set(cookie); string ckValue = null; //string userId = null; //if (this.Context.User.Identity.IsAuthenticated) // userId = this.Context.User.Identity.Name; if (cookie != null) { ckValue = cookie.Value;//Server.HtmlEncode(cookie.Value) ; Response.Write(cookie.Value); //Session["user"] = ckValue; } //return aticket.UserData; FormsAuthentication.RedirectFromLoginPage("UserPost.aspx", true); } catch (Exception ex) { FormsAuthentication.SetAuthCookie(userName, createPersistentCookie); } //return aticket.UserData; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)