In the course of work, JavaScript has a requirement to take values from Cookies. Js does not seem to have a ready-made method to specify the Key value to obtain the corresponding values in the Cookie. Refer to the Code on the Internet for simple implementation as follows:
1. server code. Several values are written for Cookies in Page_Load.
using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebApplication_TestJS { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Response.Cookies["DONO"].Value = "EDO1406300001"; Response.Cookies["DOID"].Value = "ABCDEFG123456"; Response.Cookies["DOSOURCE"].Value = "WUWUWUWU"; Response.Cookies["DOTYPE"].Value = "2"; } } }
2. client code. add buttons and text boxes on the page to trigger and output the obtained values.
<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "Default. aspx. cs "Inherits =" WebApplication_TestJS. _ Default "%>
3. The execution result shows that Cookies are stored in the structure in the first text box. You can extract the corresponding string as needed.