设有一个名为test的cookie,如何在asp.net和c#中读取它的值?asp的方法好像不行。
另如何读取form元素的值,例如读取文本框txt1的值

解决方案 »

  1.   

    Request.Cookies["TitleName"].ToString();
      

  2.   

    protected const String COOKIE_ORDERINFO  = "OrderInfo";
            protected const String COOKIE_ORDERID    = "OrderID";
            protected const String COOKIE_STATUS     = "OrderStatus";        protected Int32 OrderID 
            {
                get 
                {
                    HttpCookie cookieOrder = Request.Cookies[COOKIE_ORDERINFO];
                    if( cookieOrder == null )
                        HasError();                return Int32.Parse( cookieOrder.Values[COOKIE_ORDERID]); 
                }
            }        public void SetOrderCookie( Int32 orderid, StatusCode orderstatus )
            {
                HttpCookie cookieOrder = Request.Cookies[COOKIE_ORDERINFO];
                if( Request[COOKIE_ORDERINFO] == null )
                    cookieOrder = new HttpCookie(COOKIE_ORDERINFO);
                cookieOrder.Values.Clear();
                cookieOrder.Values.Add( COOKIE_ORDERID, orderid.ToString() );
                cookieOrder.Values.Add( COOKIE_STATUS, orderstatus.ToString() );
                Response.AppendCookie( cookieOrder);
            }        protected StatusCode OrderStatus
            {
                get 
                {
                    HttpCookie cookieOrder = Request.Cookies[COOKIE_ORDERINFO];
                    if( cookieOrder == null )
                        HasError();                return HandleStatusCode.Parse( cookieOrder.Values[COOKIE_STATUS]); 
                }   
            }
      

  3.   

    HttpCookie cookie=new HttpCookie("mycookie");
    cookie.Values.Add("name","zhuye");
    cookie.Values.Add("age","20");
    Response.AppendCookie(cookie);读取的时候
    HttpCookie cookie=Request.Cookies["mycookie"];
    string name=cookie.Values["name"];
    string age=cookie.Values["age"];
      

  4.   

    Request.Params[]用这个方便些.短了好多  QueryString From Cookie三个都能取
      

  5.   

    HttpCookie cookie=new HttpCookie("mycookie");
    cookie.Values.Add("name","zhuye");
    cookie.Values.Add("age","20");
    Response.cookies.add(cookie);读取的时候
    HttpCookie cookie=Request.Cookies["mycookie"];
    string name=cookie.Values["name"];
    string age=cookie.Values["age"];