0
이 MSDN 자습서를 따라 웹 응답을 얻지 만 응답을받지 못하므로 웹 요청을 보내기 위해 기본 또는 네트워크 자격 증명을 제외한 다른 것을 사용할 수 있는지 궁금합니다.System.Net.WebRequest 사용자 지정 자격
여기
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이며 관리자로 기록됩니다. 자격 증명 코드 줄을 주석 처리했거나 네트워크 자격 증명을 시도했지만 작동하지 않는 것 같습니다.
내가 콘솔 응용 프로그램에서 코드를 테스트 할 때 아, 네, 그것은
건배 진정한 속성 암호화를 제외하고 null의 자격 증명을 = 말한다!