当前位置: 代码迷 >> ASP.NET >> 判断用户是否属于某个角色?该怎么处理
  详细解决方案

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

热度:3643   发布时间:2013-02-26 00:00:00.0
判断用户是否属于某个角色?
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
  相关解决方案