We are fetching FedAuth cookie and we have a working code snippet. When we run it from a console application it works fine. But when we try to run it from a timer job it returns with response HTML login page for our URL.

From our analysis, the timer job (OWSTimer.exe) uses Network Service account which might be the issue. We have tried run with elevated privileges without any luck. We have also tried passing credentials with NetworkCredential.

How can be resolve this issue?

Cookie cookie = new Cookie();

HttpWebRequest request = (HttpWebRequest) WebRequest.Create(<URL TO FETCH>);
request.Credentials = CredentialCache.DefaultNetworkCredentials;

//request.Credentials = new NetworkCredential("<username>", "<password>");
//request.Credentials = new NetworkCredential("<username>", "<password>","<domain>");
//request.Credentials = new NetworkCredential("<username>", "<password>");

//request.UseDefaultCredentials = false;
//request.PreAuthenticate = true;
//request.Credentials = CredentialCache.DefaultNetworkCredentials;

request.Method = "GET";
request.Accept = "*/*";
request.UserAgent = CookieHelper.UserAgrnt; // User agent string

// Assign the CookieContainer object 
CookieContainer cookies = new CookieContainer();
request.CookieContainer = cookies;
request.AllowAutoRedirect = true;

// Execute the HTTP request 
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
  • 1
    Your question doesn't provide much context. First of all it's not a best practice to run SP Timer service as Network Service, best practice is to run it as Farm Admin account. Did you try PnP Authentication manager? Which kind of authentication your SharePoint server is using? What do you want to do with FedAuth cookie? – Sergei Sergeev Nov 30 '16 at 8:19
  • @Kai: I am not sure PnP Authentication manager would be there on our production farms, so we are not looking into that. With the FedAuth cookie we intend to access a site that is external to our farm. – Naveen Nov 30 '16 at 8:37
  • You can include it as part of the solution package, doing this it will be automatically available after deployment. – Sergei Sergeev Nov 30 '16 at 8:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.