public void CustomizeLogin() { // ----------------------------------------------------------------- // 注意:演示代码为了简单,这里不检查用户名与密码是否正确。 // ----------------------------------------------------------------- string loginName = Request.Form["loginName"]; if (string.IsNullOrEmpty(loginName)) return; UserInfo userinfo = new UserInfo(); int.TryParse(Request.Form["UserId"], out userinfo.UserId); int.TryParse(Request.Form["GroupId"], out userinfo.GroupId); userinfo.UserName = Request.Form["UserName"]; // 登录状态100分钟内有效 MyFormsPrincipal<UserInfo>.SignIn(loginName, userinfo, 100); TryRedirect(); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; UserInfo userinfo = new UserInfo { UserName = "******", UserId = 78, GroupId = 1 }; string json = new JavaScriptSerializer().Serialize(userinfo); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 2, "cbfjay", DateTime.Now, DateTime.Now.AddDays(1), true, json); string encryptedTicket = FormsAuthentication.Encrypt(ticket); FormsAuthenticationTicket ticket2 = null; Stopwatch watch =Stopwatch.StartNew(); for (int i = 0; i < 100000; i++) ticket2 = FormsAuthentication.Decrypt(encryptedTicket); watch.Stop(); context.Response.Write(watch.Elapsed.ToString()); }