<location path ="admin">
<system.web >
<authorization >
<allow roles ="admin"/>
<deny users ="*"/>
</authorization>
</system.web>
</location>
中的角色不起作用?
<system.web >
<authorization >
<allow roles ="admin"/>
<deny users ="*"/>
</authorization>
</system.web>
</location>
中的角色不起作用?
解决方案 »
- 求GridView 显示数据库中几个字段的和
- 关于Gridview 显示问题
- MVC学习遇到的错误
- ASP.NET(C#)静态类与并发问题!
- treeview
- 莫名其妙的问题,我快疯了……
- 大家帮帮我呀。怎么实现网页的连续播放音乐呀?
- 在本机上页面(包含FreeTextBox控件)能正常显示,但是在别人的机子上调用这一页时,这一页都不能显示!!
- -----------各位高手,帮我看看!关于blob数据类型---------
- 如果不小心删除了工具箱中的选项卡,比如我把 Web窗体 删除了,怎么恢复它!?
- 如何跨域取得XML数据?jsonp,iframe我都搞不定,关键它也不回发数据,
- JS中 类似C#的CompareTo比较运算符
<system.web>
<authorization>
<allow users="?"/>
</authorization>
</system.web>
</location><location path="users">
<system.web>
<authorization>
<allow roles="User"/>
<deny users="*"/>
</authorization>
</system.web>
</location>
这个不起作用。我的当前用户设置的权限为:
FormsAuthenticationTicket ticket =
new FormsAuthenticationTicket(1,
"ad",
DateTime.Now,
DateTime.Now.AddMinutes(1),
false,
"admin,user");
string emTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie UserCookie = new HttpCookie(FormsAuthentication.FormsCookieName, emTicket);
Response.Cookies.Add(UserCookie);
Context.Response.Redirect(FormsAuthentication.GetRedirectUrl(this.TextBox1.Text, false));
} 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) ; //将原有的Identity加上角色信息新建一个GenericPrincipal表示当前用户,这样当前用户就拥有了role信息
}这个文件中能得到Roles 可是就是不起作用
{
FormsIdentity Id = HttpContext.Current.User.Identity as FormsIdentity;
if (Id != null)
{
return Id.Ticket.UserData.Split(new Char[] { ',' });
}
return null; }
这样就可以了。