lhstrong

博客园 首页 新随笔 联系 订阅 管理

1. 配置web.config

   <1>.允许用户角色管理,cookie中缓存角色信息

    <roleManager enabled = "true" catheRolesInCookie="true"></roleManager>

 <2>.设置安全身份验证方式

  <authentication mode="Forms">

    <forms defaultUrl="Default.aspx" loginUrl="Login.aspx" name=".ASPXAUTH" protection="All" timeout="60"></forms>

  </authentication>

  <authorization>

    <deny users="?" />

  </authorization>

  <3>.根据用户角色设置访问路径

  <location path="manger">

    <system.web>

      <authorization>

        <allow roles="manager" />

        <deny users="*" />

      </authorization>

    </system.web>

  </location>

 

  <location path="member">

    <system.web>

      <authorization>

        <allow roles="memebers" />

        <deny users="*" />

      </authorization>

    </system.web>

  </location>

2.登录界面,用户登录时管理用户角色

  userrole: 角色

  if(Roles.RoleExists(userrole))   //判断用户角色是否存在

  {

    FormsAuthentication.RedirectFromLoginPage(username,false);

  }

  else

  {

    Roles.CreateRole(userrole);

    Roles.AddUserToRole(username,userrole);

    FormsAuthentication.RedirectFromLoginPage(username,false);

  }

  

 

posted on 2009-12-10 10:44  SEA虎  阅读(456)  评论(0编辑  收藏  举报