ASP.NET-后台cookie与前台JQUERY解析cookie

时间:2023-03-09 16:37:14
ASP.NET-后台cookie与前台JQUERY解析cookie
在controller中给cookie赋值
HttpCookie cookie =newHttpCookie("pageInfo");

cookie["page_index"]= page_index.ToString();

cookie["page_count"]= page_count.ToString();

Response.AppendCookie(cookie);

另一个cookie赋值的例子

HttpCookie cookie = Request.Cookies["OldCookieName"];
cookie.Values["CompanyID"] = Convert.ToString(CompanyId);
Response.SetCookie(cookie); //SetCookie is used for update the cookies.
Response.Cookie.Add(cookie); //This is used for Add cookies.

前端用getCookie来操作cookie

$("#ui_input_btn02").click(function (){

var page_data = getCookie("pageInfo").toString();

 page_index =String(page_data).substr(,);

var new_page =Number(page_index)-;

 $.post("/Order/Page",{ data: new_page }, function (data){

var page_data = getCookie("pageInfo").toString();

 page_index =String(page_data).substr(,);

 $("#page_now").text(page_index);

 $("#test").html(data);

来自为知笔记(Wiz)