C # Implementation of Baidu Ping function to solve Baidu does not crawl the collection site problems

Source: Internet
Author: User

Website optimization must do one of the things, Baidu Ping, the initiative to push to Baidu

The article added when the call Baidu push method

        Save protected void btnSubmit_Click (object sender, EventArgs e) {if (action = = DTENUMS.A CtionEnum.Edit.ToString ())//Modify {chkadminlevel ("Channel_" + this.channel_name + "_list", Dtenum S.actionenum.edit.tostring ()); Check Permissions if (! Doedit (this.id)) {jscriptmsg ("error occurred during the save process! ", String.                    Empty);                Return } jscriptmsg ("Modify information successfully!            "," article_list.aspx?channel_id= "+ this.channel_id); } else//Add {chkadminlevel ("Channel_" + this.channel_name + "_list", Dtenums.actione Num. Add.tostring ());  Check permissions int id=doadd (); This ID for the add article returns the ID of this article that needs to be modified by adding the article's Method return ID if (! ( id>0) {jscriptmsg ("An error occurred during the save process! ", String.                    Empty);                Return }//Get channel template name if (channel_id = = | | channel_id = = | | 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;//such as generated URLs such as http://www.qishunnet.com/knowledge_show_132.html                                      string info = DTcms.Common.BaiDu.sendUrlToBaidu (URL); Jscriptmsg ("Add information successfully! "," article_list.aspx?channel_id= "+ this.channel_id +" &message= Added information successfully!                    Baidu Push Return message = "+ info +" URL: "+ url[1]);                Return } jscriptmsg ("Add information successfully!            "," article_list.aspx?channel_id= "+ this.channel_id); }        }

Common class Library added Baidu Ping method

Using system;using system.collections.generic;using system.linq;using system.text;namespace DTcms.Common{//<        Summary>///Baidu///</summary> public class Baidu {///<summary>//push link to Baidu </summary>//<param name= "URLs" > Link collection </param>//<returns></returns&        Gt 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); Set the relevant parameters for the submission System.Net.HttpWebRequest request = System.Net.WebRequest.Create (Formurl) as System.Net.Htt                Pwebrequest; 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 Request data System.IO.Stream OutputStream = requests.                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; return value Assignment reader.                Close ();            return result; } catch (Exception ex) {return ex.            Message; }        }    }}

C # To implement Baidu Ping function to solve Baidu does not crawl the inclusion of the site's problems

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.