最好比较简单的要求单个用户可添加多个角色,最好附上表的结构,越清楚明白越好啊!呵呵!终于等到中秋节了,祝大家中秋快乐!

解决方案 »

  1.   

    大概在这里找C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallMembership.sql, InstallProfile.SQL, InstallRoles.sql
      

  2.   

    表结构,针对复杂
    --------
    用户表 userinfo(uid,uname,……) 
    角色表 role(rid,rdesc,……)
    用户角色关系表 userrole(uid,rid)
    权限表 popeom(pid,pdesc,……)//可以定义到页面级或者控件级,一般写死
    权限角色表 popeomrole(pid,rid)
    --------------------------
    页面认证
    ----
    if(!ispostback)
    {
        if(Session["userrole"]!=null)
         {
             List<string> listUserRole = Session["userrole"] as List<string>;
             if(listUserRole.contains("权限ID"))//登录成功后把用户的角色放到 Session或者其他变量中,个人习惯将角色放到泛形中 List<string> listUserRole;
             {
                  有权限;
             }
             else
             {
                  没权限;
             }
         else
         {
              没有登录,返回首页
         }
    }
      

  3.   

    定力推荐ms 的 membership 这里有整套的权限控制
      

  4.   

    NET权限管理系统
      

  5.   

    用户表 userinfo(uid,uname,roleId,...)  
    角色表 role(rid,rname,...)
    if(!ispostback)
    {
      if(Session["role"]==null)
      {Response.Redirdct("");}
    }http://www.51aspx.com/S/%E6%9D%83%E9%99%90%E7%AE%A1%E7%90%86.html
      

  6.   

    ASP.NET常用身份验证:windows 和Forms。window常用于同一个域的用户,比喻公司内部网站。Forms是一种基于Cookie的认证方式。由于Forms 的认证方式更普遍。以下是自己定制Forms认证的方式:一:修改配置文件:设置认证方式。<authentication mode="Forms">
       <forms name="test" loginUrl="Default.aspx" defaultUrl="index.aspx" protection="All"></forms>
      </authentication>二:设置网站文件的角色权限。例如:只有admin能访问admin目录下的文件<location path="admin">
      <system.web>
       <authorization>
        <allow roles="admin"/>
        <deny users="*"/>
       </authorization>
      </system.web>
     </location>三:设置自定义的角色提供者。<roleManager defaultProvider="MyRoleProvider"
          enabled="true"
          cacheRolesInCookie="true"
          cookieName=".ASPROLES"
          cookieTimeout="30"
          cookiePath="/"
          cookieRequireSSL="false"
          cookieSlidingExpiration="true"
          cookieProtection="All" >
          <providers>
            <clear />
            <add name="MyRoleProvider"
              type="MyRoleProvider"
              writeExceptionsToEventLog="false" />
          </providers >
        </roleManager >四:实现MyRoleProvider类。public class MyRoleProvider : RoleProvider
    {
        public override string[] GetRolesForUser(string username)
        {
            FormsIdentity Id = HttpContext.Current.User.Identity as FormsIdentity;
            if (Id != null)
            {
                return Id.Ticket.UserData.Split(new Char[] { ',' });
            }
            return null;    }/****** 实现RoleProvider的抽象方法。******/}五:设置用户的票证。其中包含用户的角色信息。if (/*用户合法的情况*/)
            {
                string userRole = "admin";//模拟角色可以在数据库中设置
                FormsAuthenticationTicket ticket =
                    new FormsAuthenticationTicket(1,
                                                   TextBox1.Text,
                                                   DateTime.Now,
                                                   DateTime.Now.AddMinutes(1),
                                                   false,
                                                   userRole);//用户角色
                string emTicket = FormsAuthentication.Encrypt(ticket);
                HttpCookie UserCookie = new HttpCookie(FormsAuthentication.FormsCookieName, emTicket);
                Response.Cookies.Add(UserCookie);
                string[] user = new string[] { TextBox1.Text };
                Context.Response.Redirect(FormsAuthentication.GetRedirectUrl(this.TextBox1.Text, false));
            }