web.fonfig<authentication mode="Forms">
<forms name=".fuck" path="/" loginUrl="*.aspx" protection="All" />
</authentication>
<authorization>
<deny users="?"/>
</authorization>

解决方案 »

  1.   

    using using System.Web.Security;FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,"名称",DateTime.Now,DateTime.Now.AddMinutes(60),false,".fuck");
    HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName,FormsAuthentication.Encrypt(ticket) );
    cookie.Expires=DateTime.Now.AddMinutes(60);//过期时间,这里60为分钟数
    Response.Cookies.Add(cookie);
      

  2.   

    页面调用
    //取用户名
    User.Identity.Name
    //注销用户
    //将cookies设置为过去的时间,使其失效,从而进行Forms验证
    HttpCookie cookie = new HttpCookie(".fuck");
    cookie.Expires=Convert.ToDateTime("1980-2-3");
    Response.AppendCookie(cookie);
      

  3.   

    see:
    - Role-based Security with Forms Authentication 
    http://www.codeproject.com/aspnet/formsroleauth.asp
      

  4.   

    login.aspx.cs//从数据库读取用户的权限
    string role=reader.GetInt32(0).ToString();
    //产生 Ticket
    FormsAuthenticationTicket userTicket=new FormsAuthenticationTicket(1,uid,
    DateTime.Now,DateTime.Now.AddMinutes(30),true,role,"login");//加密票据
    string hashUserTicket=FormsAuthentication.Encrypt(userTicket);
    //产生新的Cookie
    HttpCookie userCookie=new HttpCookie("login",hashUserTicket);
    Response.Cookies.Add(userCookie);
    //返回用户原来返回的页面
    Context.Response.Redirect(Context.Request["ReturnUrl"],true);global.asax.csprotected void Application_AuthenticateRequest(Object sender, EventArgs e)
    {
            HttpApplication app=(HttpApplication)sender;
    HttpContext ctx=app.Context;
    //如果验证成功
    if(ctx.Request.IsAuthenticated==true)

        FormsIdentity typeID=(FormsIdentity)ctx.User.Identity;
        FormsAuthenticationTicket ticket=typeID.Ticket;
        string []role=ticket.UserData.Split(',');
        ctx.User=new GenericPrincipal(typeID,role);
    }
    }文件夹底下的web.config的培植
    <authorization>
    <allow roles="1"/>
    <deny users="*"/>
    </authorization>我的权限 role 有三种, 为这三个权限建立三个 文件夹要 导入的命名空间using System.Web.Security;
    using System.Security.Principal;
    web.config 的配置
    <authentication mode="Forms">
    <forms name="login" path="/" loginUrl="login.aspx">
    <credentials passwordFormat="Clear">
    <user name="guest" password="guest"/>
    </credentials> 
    </forms> 


    </authentication> 

    <authorization>
    <deny users="?"/>
    </authorization>起始页为 default.aspx, 登陆页面为login.aspx ;