示例#1
0
 private void EnsureFormDigest()
 {
     if (this.m_formDigestInfo == null || DateTime.UtcNow >= this.m_formDigestInfo.Expiration)
     {
         this.m_formDigestInfo = this.GetFormDigestInfoPrivate();
     }
 }
示例#2
0
        private FormDigestInfo GetFormDigestInfoPrivate()
        {
            string             sitesAsmxUrl       = this.GetSitesAsmxUrl();
            WebRequestExecutor webRequestExecutor = base.WebRequestExecutorFactory.CreateWebRequestExecutor(this, sitesAsmxUrl);

            this.FireExecutingWebRequestEventInternal(new WebRequestEventArgs(webRequestExecutor));
            webRequestExecutor.RequestContentType           = "text/xml";
            webRequestExecutor.RequestHeaders["SOAPAction"] = "http://schemas.microsoft.com/sharepoint/soap/GetUpdatedFormDigestInformation";
            if (base.AuthenticationMode == ClientAuthenticationMode.Default)
            {
                webRequestExecutor.RequestHeaders["X-RequestForceAuthentication"] = "true";
            }
            this.BuildGetUpdatedFormDigestInfoRequestBody(webRequestExecutor.GetRequestStream());
            //Edited for .NET Core - Calling dispose does not work because now they are Async methods
            //webRequestExecutor.GetRequestStream().Close();
            //webRequestExecutor.GetRequestStream().Dispose();// Close();
            try
            {
                webRequestExecutor.Execute();
            }
            catch (WebException webEx)
            {
                string text = this.ExtractSoapError(webEx);
                if (string.IsNullOrEmpty(text))
                {
                    throw;
                }
                throw new ClientRequestException(Resources.GetString("CannotContactSiteWithDetails", new object[]
                {
                    base.Url,
                    text
                }));
            }
            if (webRequestExecutor.StatusCode != HttpStatusCode.OK || webRequestExecutor.ResponseContentType.IndexOf("text/xml", StringComparison.OrdinalIgnoreCase) < 0)
            {
                throw new ClientRequestException(Resources.GetString("CannotContactSite", new object[]
                {
                    base.Url
                }));
            }
            FormDigestInfo formDigestInfo = this.ParseFormDigest(webRequestExecutor.GetResponseStream());

            if (formDigestInfo == null)
            {
                throw new ClientRequestException(Resources.GetString("CannotContactSite", new object[]
                {
                    base.Url
                }));
            }
            return(formDigestInfo);
        }