The first thing you need to understand about cookies is this: Cookies carry an expiry date.Every time you set the Value of a cookie, remember also to set the Expires date. If you fail to do this you will quickly find yourself losing Cookies owing to them having expired immediately when updating them on the client machine.
Response.Cookies["Cookie_role"].Value = "v_role";
Response.Cookies["Cookie_role"].Expires = DateTime.Now.AddDays(1);

解决方案 »

  1.   

    读取:
    HttpCookie mycookie=Request.Cookies["Cookie_role"];
    string role_name=mycookie.Value;
      

  2.   

    dy_2000_abc(芝麻开门) :
    还是没读出来!!
      

  3.   

    Can you show the whole codes?
      

  4.   

    我在用户登录成功后,使用:
    HttpCookie mycookie=new HttpCookie("Cookie_role");
    mycookie.Value=v_role;
    Response.AppendCookie(mycookie);
    将用户角色存入cookie,目地就是为了在以后取出(类似于CS中的全局变量)。
    然后在主网页打开时,先进行用户角色判断,再根据角色类型,定制用户菜单,为此,我先用
    HttpCookie mycookie=Request.Cookies["Cookie_role"];
    string role_name=mycookie.Value;
    将上面Cookie中的值取出,但取出结果为空(但不报错!)我在Web.config中的设置为:
        <authentication mode="Forms">
        <forms  loginUrl="login.aspx" />
    </authentication>

    <authorization>
    <deny users="?" />
    </authorization>    
    请各位帮我找一下原因!!