我的网站分几级权限:前台都可以浏览,后台(Manage目录)只有会员才可以(管理员包括在里面),然后在后台的网站信息设置页面(Manage/WebSet.aspx)里,要求只有管理员才能进.目前后台是用的Forms身份验证,相关代码如下:
<authentication mode="Forms"> 
        <forms name="ChrisLiu" loginUrl="Login.aspx" protection="All" timeout="30" path="/" />
</authentication><authorization>
        <allow users="*" />
</authorization><location path="Manage">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>请问怎么办???还用Forms验证来设置Manage下的WebSet目录,可以吗???.我不想再用Session或Cookie了(麻烦死了),却找不到解法.

解决方案 »

  1.   

    那你的 WebSet目录,用什么来区分是不是管理员?
      

  2.   

    没有WebSet目录,只有Manage下面的WebSet.aspx文件程序里加身分验证我说过了啊,很麻烦啊.如果按登录后的用户名来在config文件里配置就更好了,就是不知道有没有这个功能.我试了,似乎不行.
      

  3.   

    这样试试:<authentication mode="Forms"> 
            <forms name="ChrisLiu" loginUrl="Login.aspx" protection="All" timeout="30" path="/" >
            </forms>
     
            <credentials passwordFormat="Clear">
               <user name="admin1" password="pwd1" />
               <user name="admin2" password="pwd2" /> 
            </credentials>
    </authentication>
      

  4.   

    在Manage加入web.config。
    <location path="Manage/WebSet.aspx">
    <system.web>
    <authorization>
                                <allow roles="admin" />
    <deny users="?" />
    </authorization>
    </system.web>
    </location>然后在Global.asax.cs中的Application_AuthenticateRequest事件中写如下代码:
    // 映射用户的权限 [3/5/2005]
    HttpApplication app = (HttpApplication)sender;
    if (app.Request.IsAuthenticated &&
    app.User.Identity is FormsIdentity)// 如果请求已经通过验证,并且验证模式是“窗体验证" [3/5/2005]
    {
    FormsIdentity indentity = (FormsIdentity)app.User.Identity; // 得到用户的角色 [3/5/2005]
    DataSet ds = BusinessRules.sysMana.sysManaRules.GetPermissionModules(indentity.Name);

    if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
    {
    StringBuilder sb = new StringBuilder();
    foreach(DataRow dr in ds.Tables[0].Rows)
    {
    sb.Append(dr["RoleName"].ToString() + ",");
    }
    string[] roles = sb.ToString().Split(new char[] {','});
    if (roles != null)
    {
    app.Context.User = new GenericPrincipal(indentity, roles);
    string strURL = this.Request.ApplicationPath;
    }
    }
      

  5.   

    o2delphi(花满楼)好像说得有理,可是代码.....汗~~~~~~~~可能我这样做比较麻烦吧,还不如用Session或Cookie.