MSDN地址:
ms-help://MS.MSDNQTR.v90.chs/dv_aspnetgenref/html/144e9a7c-d94f-4dd4-be3a-b47d0e1ced47.htm示例:
下面的代码示例演示如何拒绝对所有用户帐户的访问,以及允许对 admins 角色的所有成员的访问。
<configuration>
  <system.web>
    <authorization>
      <allow roles="admins"/>
      <deny users="*"/>
    </authorization>
  </system.web>
</configuration>我实在不知道微软怎么做到的!试了N变,明明是拒绝了所有用户,包括admins角色的拒绝了。愿高手赐教,大家探讨!

解决方案 »

  1.   

           <deny users="*"/> 
    <allow roles="admins"/> 
      

  2.   

    后台操作没有?System.Web.Security.FormsAuthentication.SetAuthCookie("admins", true);
      

  3.   

     Login(name, "admins", false);       public static void Login(string username, string roles, bool isPersistent)
            {
                DateTime dt = isPersistent ? DateTime.Now.AddMinutes(99999) : DateTime.Now.AddMinutes(60);
                //初始化一个用户凭证的实例
                FormsAuthenticationTicket myTicket = new FormsAuthenticationTicket(1, username, DateTime.Now, dt, false, roles);
                string encryptedTicket = FormsAuthentication.Encrypt(myTicket); //加密用户凭证            //把用户凭证存入Cookie 
                HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                //将cookie的失效时间设置为和票据tikets的失效时间一致 
                if (myTicket.IsPersistent)
                {
                    authCookie.Expires = myTicket.Expiration;
                }
                //添加cookie到页面请求响应中
                System.Web.HttpContext.Current.Response.Cookies.Add(authCookie);
            }fenglaijun:后面要true吗?按MSDN意思不用的呀
    jzywh :什么叫“roles 你没加进去”?谢谢
      

  4.   

    看看这个就明白了
    http://topic.csdn.net/u/20070512/12/fa8a75c3-dddf-49f7-bc89-590126c9dcb2.html
      

  5.   

    用这个没有啊
    Application_PostAuthenticateRequest
    你用的是什么事件的啊??这种问题一艘一大堆
    先自己搜下啊
      

  6.   

    roles没有加进去就是
    角色没有加进去
      

  7.   

    果然我写在Application_AuthenticateRequest里了实在有劳几位高手帮助了但是,更重要的问题来了
    我现在赋予多重角色,我用循环重复赋角色肯定不行了。
    现在有了7种用户类型进7个子系统,账号可以具有多种用户类型,这样做,需要定义7*6*5*4*3*2种角色了怎么办?
      

  8.   

    FormsAuthenticationTicket myTicket = new FormsAuthenticationTicket(1, username, DateTime.Now, dt, false, roles);
    执行N次不起作用呀。。