0
試圖按照此MSDN教程來獲取Web響應,但沒有得到任何迴應,所以想知道如果我可以使用除默認或網絡憑證之外的其他任何內容來發送Web請求。System.Net.WebRequest自定義證書
我使用它在SharePoint自定義計時器作業安裝在使用功能接收器,這裏的代碼,
計時器作業類execute方法
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.Diagnostics;
namespace EmailJob.FeatureCode
{
class SharePointWarmupJob : SPJobDefinition
{
private const string JOB_NAME = "Email Job";
public SharePointWarmupJob() : base() { }
public SharePointWarmupJob(SPWebApplication webApp)
: base(JOB_NAME, webApp, null, SPJobLockType.ContentDatabase)
{
this.Title = JOB_NAME;
}
public override void Execute(Guid targetInstanceId)
{
Debug.Assert(false);
if (this.WebApplication.Sites.Count > 0)
WarmUpSharePointSite(this.WebApplication.Sites[0]);
}
private void WarmUpSharePointSite(SPSite siteCollection)
{
System.Net.WebRequest request = System.Net.WebRequest.Create(siteCollection.Url);
request.Credentials = System.Net.CredentialCache.DefaultCredentials;
request.Method = "GET";
System.Net.WebResponse response = request.GetResponse();
response.Close();
}
}
}
功能接收器類
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using EmailJob.FeatureCode;
namespace EmailJob
{
class EmailJobFeature : SPFeatureReceiver
{
private const string JOB_NAME = "Email Job";
public override void FeatureInstalled(SPFeatureReceiverProperties properties)
{
throw new NotImplementedException();
}
public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
{
throw new NotImplementedException();
}
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
if (webApp == null)
throw new NotImplementedException("Error obtaining reference to Web application");
foreach (SPJobDefinition job in webApp.JobDefinitions)
if (job.Name == JOB_NAME) job.Delete();
SharePointWarmupJob warmupJob = new SharePointWarmupJob(webApp);
SPMinuteSchedule schedule = new SPMinuteSchedule();
schedule.BeginSecond = 0;
schedule.EndSecond = 59;
schedule.Interval = 5;
warmupJob.Schedule = schedule;
warmupJob.Update();
}
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
SPWebApplication webApp = properties.Feature.Parent as SPWebApplication;
if (webApp == null)
throw new NotImplementedException("Error obtaining reference to Web application");
foreach (SPJobDefinition job in webApp.JobDefinitions)
if (job.Name == JOB_NAME) job.Delete();
throw new NotImplementedException();
}
}
}
當我嘗試調試時,它在代碼行沒有迴應
"System.Net.WebResponse response = request.GetResponse();"
這是我的VPC,並以管理員身份登錄,我甚至註釋了憑據代碼行或嘗試過網絡憑據,但它似乎不起作用。
哦,是的,當我嘗試測試在控制檯應用程序代碼,它說的憑據屬性,除了加密空=真
乾杯!