用.net本身提供的membership管理可以轻松达到你的要求

解决方案 »

  1.   

    write cookie:
    HttpCookie cookie1 = new HttpCookie("UserID");
    cookie1.Value = sdr["UserID"].ToString();
    Response.AppendCookie(cookie1);read cookie:
    string UserID;
    UserID= Request.Cookies["UserID"].Value.ToString();
      

  2.   

    以下我自己写的代码行吗?
    SqlConnection con=DB.con();
    SqlCommand cmd=new SqlCommand("UserLogin",con);
    cmd.CommandType=CommandType.StoredProcedure; SqlParameter Uname=new SqlParameter("@UName",SqlDbType.NVarChar,16);
    Uname.Value=TextBox1.Text;
    cmd.Parameters.Add(Uname); SqlParameter Pword=new SqlParameter("@PWord",SqlDbType.NVarChar,16);
    Pword.Value=TextBox2.Text;
    cmd.Parameters.Add(Pword); try
    {
    con.Open();
    SqlDataReader dr=cmd.ExecuteReader();
    if (dr.Read())
    {
    Response.Cookies["id"].Value=dr["uid"].ToString();
    dr.Close();
    FormsAuthentication.RedirectFromLoginPage(TextBox1.Text,false);
    }
    }
    catch(Exception ex)
    {
    Response.Write (ex.Message);
    }
    finally
    {
    con.Close();
    }符合标准吗?
      

  3.   

    以下是我webconfig文件设置
      <authentication mode="Forms"> 
           <forms loginUrl="Login.aspx" name="AuthCookie" timeout="60" path="/"/>
      </authentication>
      <authorization>
            <deny users="?" /> <!-- 允许所有用户 -->
        </authorization>
      

  4.   

    使用Forms的roles,另外1.1中不要使用RedirectFromLoginPage。有BUG。会产生临时票据,里面的false和true会导致cookies的永久性。
      

  5.   

    贴了好几天了,就是没一个全面的解答,CSDN怎么了?老大们都怎么了?
      

  6.   

    如果你的用户数相对固定,不是需要注册的那种.而且没有角色的话,你可以这样 <authentication mode="Forms">
            <forms defaultUrl="admin/" loginUrl="login/" name="santuchildbike" path="/" protection="All" timeout="60">
              <credentials passwordFormat ="MD5">
                <user name ="santuchildbike" password ="5A0D7C31E8E266215461AF8408E4DB2F"/>
                <user name="" password=""/>
              </credentials>
            </forms>
          </authentication>
    可以加任意多个  <user name="" password=""/>
    节点.这样实现起来方便多了