一般的管理系统使用的是Session或Cookies来对进行对用户的身份验证的,而Asp.Net本身就提供了一种验证机制:FormsAuthenticationTicket,本人觉得这种机制是基于Cookies的。定义一个用户信息类: using System;using System.Web;using System.Web.UI;using System.Web.Security;public class ShopManageUser} 登录: ShopManageUser user = new ShopManageUser();user.Id = 1;user.UserName = "faib";user.Name = "";FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, user.UserName, DateTime.Now, DateTime.Now.AddMinutes(30), false, user.ToString());string encryptedTicket = FormsAuthentication.Encrypt(authTicket);HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);HttpContext.Current.Response.Cookies.Add(authCookie); 注销:FormsAuthentication.SignOut();判断:User.Identity.IsAuthenticated;使用:ShopManageShop user = ShopManageShop.GetCurrent(); 相关文章: