首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

判断用户是否属于某个角色?该怎么处理

2012-02-13 
判断用户是否属于某个角色?protectedvoidPage_Load(objectsender,EventArgse){RolePrincipalp(RolePrinci

判断用户是否属于某个角色?
protected   void   Page_Load(object   sender,   EventArgs   e)
        {
                RolePrincipal   p   =   (RolePrincipal)User;
                string[]   roles   =   p.GetRoles();
                foreach   (string   s   in   roles)
                {
                        Response.Write(s   +   " <br> ");
                }
                if   (HttpContext.Current.User.IsInRole( "PurchaseAdmin "))
                {
                        string   url;
                        url   =   "~/Default1.aspx ";
                        Response.Redirect(this.ResolveUrl(url));
                                      }
        }

运行时出以下错,以前我好像解决过,但重装操作系统后问题就解决不了.?????
错误如下:
无法将类型为“System.Security.Principal.WindowsPrincipal”的对象强制转换为类型“System.Web.Security.RolePrincipal”。

[解决办法]
((RolePrincipal)Page.User.Identity).IsInRole

热点排行