首页 > 代码库 > sharepoint warmup

sharepoint warmup

/---------------- using System;using System.Collections.Generic;using System.Text;using System.Net;namespace WarmupSharepointCS{    class Program    {        static void Main(string[] args)        {            string url = "https://www.sp.net";            string url2 = "https://www.sp.net/_windows/default.aspx?ReturnUrl=";            string user = "user";            string pwd = @"pwd";            long count = 0;            System.Threading.Timer t = new System.Threading.Timer(callback => {                if (System.DateTime.Now.Hour >= 5 && System.DateTime.Now.Hour < 21)                try                {                    string authInfo = user + ":" + pwd;                    authInfo = Convert.ToBase64String(Encoding.UTF8.GetBytes(authInfo));                    var webclient = new WebClient2();                    webclient.Headers[HttpRequestHeader.Authorization] = "Basic " + authInfo;                    var webpage = webclient.DownloadString(url2);                    var str2 = webclient.DownloadString(url);                    Console.ForegroundColor = System.ConsoleColor.Green;                    Console.WriteLine(webpage);                }                catch (Exception ex)                {                    Console.ForegroundColor = System.ConsoleColor.Red;                    Console.WriteLine(ex.Message);                }                count++;                Console.WriteLine("timer:" + count.ToString());            },null,0,1000*60 * 20);                        Console.Read();        }    }} //---------------- ///////////////////////////////using System;using System.Collections.Generic;using System.Net;namespace WarmupSharepointCS{    public class WebClient2:System.Net.WebClient    {        private readonly CookieContainer m_container = new CookieContainer();        protected override WebRequest GetWebRequest(Uri address)        {            WebRequest request = base.GetWebRequest(address);            HttpWebRequest webRequest = request as HttpWebRequest;            if (webRequest != null)            {                webRequest.CookieContainer = m_container;            }            return request;        }    }} //////////////////////////////////