积极答复者
Global文件判断session 的用户名

问题
-
登录时,取到用户名和角色, 保存为
Session["Account"] = UserName;
Session["Roles"] = UserRoles;
在Global.asax文件中,写下:
protected void Application_AuthenticateRequest(object sender, System.EventArgs e)
{
HttpApplication App = (HttpApplication)sender;
HttpContext Ctx = App.Context;if (Ctx.Request.IsAuthenticated == true) //验证过的用户才进行role的处理
{
FormsIdentity Id = (FormsIdentity)Session["Account"];
string TempRoles = Session["Roles"].ToString();
string[] Roles = TempRoles.Split(',');
Ctx.User = new GenericPrincipal(Id, Roles);
}
}
无法执行角色组的权限,不知道毛病出在哪里?
答案
-
谢谢!
都在磁盘上
查了FormsAuthentication的资料, 好像只支持票据传输。认命了。
再问一下,下面两句的命令
Context.Response.Cookies.Add (UserCookie) ; //这句是直接写在客户端的硬盘上吗?
Context.Response.AppendCookie(UserCookie); //这句是写在客户端的内存缓存吗?FormsAuthentication 可以使用UserData传递更多的信息。不过cookie有大小限制的。验证信息不应当传递复杂的对象信息。即使Session,存储很多对象也是不好的。
【孟子E章】- 已标记为答案 lfj0912 2009年11月18日 7:02
全部回复
-
protected void Application_AuthenticateRequest(object sender, System.EventArgs e)
{
HttpApplication App = (HttpApplication)sender;
HttpContext Ctx = App.Context;if (Ctx.Request.IsAuthenticated == true)
{
string GenId = Ctx.Session["Account"].ToString();
GenericIdentity MyIdentity = new GenericIdentity(GenId);string TempRoles = Ctx.Session["Roles"].ToString();
string[] MyStringArray = TempRoles.Split(',');Ctx.User = new GenericPrincipal(MyIdentity, MyStringArray);
}
}
不知道怎么办?这样还不行? -
谢谢!
都在磁盘上
查了FormsAuthentication的资料, 好像只支持票据传输。认命了。
再问一下,下面两句的命令
Context.Response.Cookies.Add (UserCookie) ; //这句是直接写在客户端的硬盘上吗?
Context.Response.AppendCookie(UserCookie); //这句是写在客户端的内存缓存吗?FormsAuthentication 可以使用UserData传递更多的信息。不过cookie有大小限制的。验证信息不应当传递复杂的对象信息。即使Session,存储很多对象也是不好的。
【孟子E章】- 已标记为答案 lfj0912 2009年11月18日 7:02