haha为用户名
1.System.Web.Security.FormsAuthentication.RedirectFromLoginPage("haha", false);
2.System.Web.Security.FormsAuthentication.SetAuthCookie("haha",false);
Response.Redirect("default.aspx");
3. System.Web.Security.FormsAuthenticationTicket tk = new System.Web.Security.FormsAuthenticationTicket(1,
"haha",
DateTime.Now,
DateTime.Now.AddMonths(1),
true,
"",
System.Web.Security.FormsAuthentication.FormsCookiePath
);
string key = System.Web.Security.FormsAuthentication.Encrypt(tk); //得到加密后的身份验证票字串
HttpCookie ck = new HttpCookie(System.Web.Security.FormsAuthentication.FormsCookieName, key);
//ck.Domain = System.Web.Security.FormsAuthentication.CookieDomain; // 这句话在部署网站后有用,此为关系到同一个域名下面的多个站点是否能共享Cookie
HttpContext.Current.Response.Cookies.Add(ck);
Response.Redirect("default.aspx");