//登陆:
user="用户名";
System.Web.Security.FormsAuthentication.SetAuthCookie(user, false);
//判断是否登陆(这样判断客户端是否可以伪造?)if (!Context.User.Identity.IsAuthenticated)
{
}假如说上面的代码是安全的,那么这样一个问题就出来了,这种登陆只能保存一个参数(user),
那如果要把,user,pass,power,sex,name等都安全的保存到这里面怎么办?
user="用户名";
System.Web.Security.FormsAuthentication.SetAuthCookie(user, false);
//判断是否登陆(这样判断客户端是否可以伪造?)if (!Context.User.Identity.IsAuthenticated)
{
}假如说上面的代码是安全的,那么这样一个问题就出来了,这种登陆只能保存一个参数(user),
那如果要把,user,pass,power,sex,name等都安全的保存到这里面怎么办?
不安全,前几天在CSDN 上看到了一个报道,说有人通过改写COOKIE 来攻击网络程序
那如果要把,user,pass,power,sex,name等都保存到这里面怎么办?
还有就是保存后如何读取? ======================================================================
那如果要把,user,pass,power,sex,name等都保存到这里面怎么办?
还有就是保存后如何读取? -----------------
你可以自定义票据,里面有个USERDATA扩展字段,这样你就可以多存点东西啦
它是由权限,用户名,密码联合起来进行加密。验证Cookie是否被篡改就验证这个值
-----------------------------------------------------------
如何自定义票据?有例子吗,给一个
这个是加密的.安全.还可以自定义加密方法,WEBCONFIG配置下.你可以类似这样操作票据:
FormsAuthentication.SetAuthCookie(userName, false);
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1,
userName,
DateTime.Now,
DateTime.Now.AddMinutes(60),
false,
Roles.GetRolesForUser(userName).ToString()
);
string hashTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hashTicket);
cookie.Expires = DateTime.Now.AddMinutes(60);
ControllerContext.HttpContext.Response.Cookies.Add(cookie);