C # implement the Baidu ping function,
One of the things that must be done for website optimization is Baidu ping, which is actively pushed to Baidu
Call Baidu push method when adding an article
// Save protected void btnSubmit_Click (object sender, EventArgs e) {if (action = DTEnums. actionEnum. edit. toString () // modify {ChkAdminLevel ("channel _" + this. channel_name + "_ list", DTEnums. actionEnum. edit. toString (); // check the permission if (! DoEdit (this. id) {JscriptMsg ("An error occurred while saving! ", String. Empty); return;} JscriptMsg (" Information modified successfully! "," Article_list.aspx? Channel_id = "+ this. channel_id);} else // Add {ChkAdminLevel ("channel _" + this. channel_name + "_ list", DTEnums. actionEnum. add. toString (); // check the permission int id = DoAdd (); // This id is the id of the article returned by the add article. You need to modify the method of adding the article and return the id if (! (Id> 0) {JscriptMsg ("An error occurred while saving! ", String. empty); return ;} // obtain the Channel Template Name if (channel_id = 13 | channel_id = 16 | channel_id = 18 | channel_id = 25 | channel_id = 6) {string channelTemp = new BLL. channel (). getModel (this. channel_id ). name. toString (); string articleUrl = new BasePage (). linkurl (channelTemp + "_ show", id); string [] url = new string [100]; url [1] =" http://www.qishunnet.com "+ ArticleUrl; // For example, the generated url is as follows: http://www.qishunnet.com /Knowledge_show_132.html string info = DTcms. Common. BaiDu. sendUrlToBaidu (url); JscriptMsg ("information added successfully! "," Article_list.aspx? Channel_id = "+ this. channel_id +" & message = information added! Baidu push return information = "+ info +" url: "+ url [1]); return;} JscriptMsg (" information added successfully! "," Article_list.aspx? Channel_id = "+ this. channel_id );}}
Add the Baidu ping method to the common class library
Using System; using System. collections. generic; using System. linq; using System. text; namespace DTcms. common {// <summary> /// BaiDu-related classes /// </summary> public class BaiDu {/// <summary> /// push link to BaiDu /// </summary> /// <param name = "urls"> link set </param> /// <returns> </returns> public static string sendUrlToBaidu (string [] urls) {try {string formUrl =" http://data.zz.baidu.com/urls?site=www.qishunnet.com&token=FdSmdb3LRa4JitQp "; String formData =" "; foreach (string url in urls) {formData + = url +" \ n ";} byte [] postData = System. text. encoding. UTF8.GetBytes (formData); // sets the System parameter for submission. net. httpWebRequest request = System. net. webRequest. create (formUrl) as System. net. httpWebRequest; System. text. encoding myEncoding = System. text. encoding. UTF8; request. method = "POST"; request. keepAlive = false; request. allowAutoRedirect = true; request. contentType = "text/plain"; request. userAgent = "curl/7.12.1"; request. contentLength = postData. length; // submit the request data System. IO. stream outputStream = request. getRequestStream (); outputStream. write (postData, 0, postData. length); outputStream. close (); System. net. httpWebResponse response; System. IO. stream responseStream; System. IO. streamReader reader; string srcString; response = request. getResponse () as System. net. httpWebResponse; responseStream = response. getResponseStream (); reader = new System. IO. streamReader (responseStream, System. text. encoding. getEncoding ("UTF-8"); srcString = reader. readToEnd (); string result = srcString; // The returned value is reader. close (); return result;} catch (Exception ex) {return ex. message ;}}}}