In the article to introduce the micro-letter enterprise development of micro-letter attendance Baidu map positioning, and then through the study of micro-letter enterprise development of micro-letter attendance cookies Use, the specific contents are as follows.
Using micro-credit attendance, each use of micro-credit enterprise development: the relationship between micro-credit user Information and Web page session the inside method, call the micro-letter interface, a bit slow, micro-letter official also recommended the use of cookies, but how to use cookies, they have not been clear.
Originally thought in the server to obtain the client's data have two methods, one is to put the query string on the URL, one is placed in the form, post submitted, I have used before, but mainly in the client use, can never put the data in cookies directly to the service side, Even if there is a hidden field in the form by reading the data from the cookie, then post it to the server.
Obviously micro-credit attendance is actually a URL, in the process of entering the URL, there is no post data process. Only after entering the URL and then submitting via user, or Ajax submission. In short, it seems impossible to directly submit the data in cookies directly to the server. Seems to be in deadlock. So I studied cookies once again, and found that cookies appear to be submitted to the server, but it's not the same location as post, and of course I didn't find the documentation, the test found. As long as you set cookies, each entry URL will be submitted to the cookies, you can naturally read the value of cookies on the server. Then really understand how to remember the true principle of the password. Not to read the value of cookies, put the hidden fields, and then through the Ajax submitted to the server, you can be free of landing.
Cookies can be seen on the service side, SessionID also through the way of cookies to the service side.
Front-end JS read, set Cookies method:
function Setcookie (name, value) {///two parameters, one is the name of the cookie, one is the value
var days = 30;//This cookie will be saved 30 day
var exp = new Date () ; New Date ("December, 9998");
Exp.settime (Exp.gettime () + days * * * * 1000);
Document.cookie = name + "=" + Escape (value) + "expires=" + exp.togmtstring ();
}
function GetCookie (name) {//Fetch cookies function
var arr = document.cookie.match (New RegExp ("(^|)" + name + "= ([^;] *)(;|$)"));
if (arr!= null) return unescape (arr[2)); return null;
CSharp service-side operation Cookies:
Set cookies
HttpCookie cookies = new HttpCookie ("Usercode", username);
Cookie. Expires = DateTime.Now.AddDays (a);//(365 * 3600);
This. Response.appendcookie (cookie);
HttpCookie Cookiedeviceid = new HttpCookie ("DeviceId", Rt. DEVICEID);
Cookiedeviceid.expires = DateTime.Now.AddDays (10);//(365 * 24 * 3600);
Read cookies:
HttpCookie Tthttpcookie = this. Request.Cookies.Get ("Usercode");
HttpCookie Tthttpcookiedeviceid = this. Request.Cookies.Get ("DeviceId");
String code = request.querystring["Code"];
if (Tthttpcookie = null | | tthttpcookiedeviceid = null)
{
Weiapi (code);
}
else {
string username = Tthttpcookie.value;
string DeviceId = Tthttpcookiedeviceid.value;
if (string. IsNullOrEmpty (username) | | String. IsNullOrEmpty (DeviceId))
{
Weiapi (code);
}
else {
new appexception ("Read cookies usercode=" + username + ", deviceid=" + DeviceId);
Initsession (username, DeviceId);
}
The above content to introduce the micro-letter enterprise development of micro-letter attendance Cookies Use, I hope you like.