Difference between Request.Cookies and Response.Cookies

前端 未结 4 2037
孤街浪徒
孤街浪徒 2021-01-31 15:16

I use both of these many times in my code and don\'t really know what the difference is , if a cookie is set shouldn\'t it be exactly the same in request and response? and is re

4条回答
  •  难免孤独
    2021-01-31 15:39

    The word Response is used in Asp.net to send data from the server to the client and the Request is used to get the data from the client ( in the form of cookies, query string ) etc. Example:

    Response.Write("will write the content on the form which will return to the client");
    // Response.Cookies will send the cookie to the client browser.
     Response.Cookies.Add(HttpCookie("MyCookie", "MyValue"))
    //and Request.Cookies is used to get the cookie value which is already present in the clinet browswer   
    

    and as you mentioned

    string a = HttpContext.Current.Request.Cookie["a"].Value;
    // I think this will check the cookie which is present in the client browser [ If client has sent the cookie to the server ]
    
    string a = HttpContext.Current.Response.Cookie["a"].Value;
    // and this will see the only Response object. If the cookie present in the response object then it will return you otherwise not.
    

提交回复
热议问题