aspx page state management cookie and ViewState_html/css_WEB-ITnose
Release: 2016-06-24 11:52:50
Original
1177 people have browsed it
- Cookie
- Set cookie
protected void Button2_Click(object sender, EventArgs e) { HttpCookie cookie = new HttpCookie("user"); cookie.Value = "这是cookie"; cookie["sex"] = "女"; cookie.Values.Add("age", "18"); cookie.Expires = DateTime.Now.AddHours(1); Response.AppendCookie(cookie);//将Cookie追加到内部cookie //Response.Cookies.Add(cookie);//跟上面一样 }
Copy after login
2 Get Cookie
protected void Button1_Click(object sender, EventArgs e) { //获取客户端发送的Cookie HttpCookie cookie1 = Request.Cookies["user"]; if (cookie1 == null) { Response.Write("木有发现cookie"); } else { Response.Write("cooki值为:"+cookie1.Value+"<br/>"); Response.Write("sex值为:"+cookie1["sex"]+"<br/>"); Response.Write("age值为:"+cookie1["age"]+"<br/>"); } }
Copy after login
3, delete cookies
//将cookie有效期设置为过去某个时间,浏览器会检查自动删除 HttpCookie cookie = Request.Cookies["user"]; cookie.Expires = DateTime.Now.AddHours(-1);
Copy after login
-
- Rendering
- Reading cookies across domains
- Cookies from different domains cannot be shared. If the site has subdomains (baiyun.com and sell, baiyun.com), you can set the Domain attribute of the cookie
cookie.Domain="baiyun.com";cookie.Domain="sell.baiyun.com";
Copy after login
so that the cookie can be used for the main domain and subdomains
- When viewing the source code on the web page, there is a hidden field of _VIEWSTATE which is: 1. The existence of the client will reduce the pressure on the server 2. It is inherently limited and can only save objects that can be serialized; 3. If it is too large, the transmission speed will be slow and increase the server's parsing burden; 4. You can use LosFormatter to get the ViewState deserialized object, which has poor security; 5. It can be turned off to improve performance (EnableViewState="false")
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31