title: System.Net.WebRequest Custom Credentials
body: <p>Trying to follow this MSDN tutorial to get a web response but not getting any response back, so wondering if I can use anything else except default or network credentials for sending a web request.</p>
  
  <p>I am using it in a Sharepoint Custom Timer Job installed using a Feature Receiver, here's the code,</p>
  
  <p>Timer Job class with execute method</p>
  
  <pre><code>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 &gt; 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();
          }
      }
  }
  </code></pre>
  
  <p>Feature Receiver class</p>
  
  <pre><code>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();
          }
      }
  }
  </code></pre>
  
  <p>When I try to debug, it gives no response back at code line </p>
  
  <pre><code>"System.Net.WebResponse response = request.GetResponse();"
  </code></pre>
  
  <p>This is my VPC and am logged as Administrator, I even commented out credentials code line or tried network credentials but it just doesn't seems to work.</p>
  
  <p>Oh yes when i try to test code in Console app, it says the credentials properties are null except encrypt = true</p>
  
  <p>Cheers ! </p>