在global.ascx.cs中:protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
HttpApplication App = (HttpApplication) sender;
HttpContext Ctx = App.Context ; //获取本次Http请求相关的HttpContext对象
if (Ctx.Request.IsAuthenticated == true) //验证过的用户才进行role的处理
{
FormsIdentity Id = (FormsIdentity)Ctx.User.Identity ;
FormsAuthenticationTicket Ticket = Id.Ticket ; //取得身份验证票
string[] Roles = Ticket.UserData.Split (',') ; //将身份验证票中的role数据转成字符串数组
Ctx.User = new GenericPrincipal (Id, Roles) ; //
}
}
{
HttpApplication App = (HttpApplication) sender;
HttpContext Ctx = App.Context ; //获取本次Http请求相关的HttpContext对象
if (Ctx.Request.IsAuthenticated == true) //验证过的用户才进行role的处理
{
FormsIdentity Id = (FormsIdentity)Ctx.User.Identity ;
FormsAuthenticationTicket Ticket = Id.Ticket ; //取得身份验证票
string[] Roles = Ticket.UserData.Split (',') ; //将身份验证票中的role数据转成字符串数组
Ctx.User = new GenericPrincipal (Id, Roles) ; //
}
}
解决方案 »
- ASP.NET MVC 发布后到IIS 运行一段后就连接不上了
- 关于代码上的一些问题,请大家进来帮我看看
- 达人高人进来关于asp.net c#时间
- .net连续刷新报错~!~
- 用ASP.NET做的登录页面,怎样让移动设备使用进行身份验证?
- 如何做这样的sql查询?
- A页面与B页面,A页面是我做的,而B页面并不由我控制,如何保证A页面要传递参数到B页面
- 如何连接做的各个网站(在线等大家帮忙),急急急
- 如何保存为<![CDATA[ *****]]>格式节点的XML文件
- 帮忙看看这段代码
- 初学oracle有问题请教:ORA-01036: 非法的变量名/编号
- 请各位高手帮忙:如何将一xml文件转换成html文件,而相对应的xsl文件不存在(急!!!)
我按你的方法处理,发现Ctx.Request.IsAuthenticated总是为false,请继续不吝赐教阿!!
vasun(新帐号):
按照该方法处理,同样出现Ctx.Request.IsAuthenticated为false问题!!
这是为什么?方法有问题么?
http://www.csdn.net/develop/read_article.asp?id=18958
http://www.codeproject.com/aspnet/formsroleauth.asp
<authentication mode="Forms">
<forms loginUrl="/Login/login.aspx" protection="All" name="AuthCookie" path="/">
</forms>
</authentication>
<authorization>
<deny users="?" />
<allow users="*" />
</authorization>
if (Ctx.Request.IsAuthenticated == true) //验证过的用户才进行role的处理
我按gshope(北京.Net) 给的连接:
http://www.codeproject.com/aspnet/formsroleauth.asp
按照这个做,可是HttpContext.Current.User总是为空!
痛苦ing
按照IBuySpy的模式处理,成功了!感谢两位!