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
How can be resolve this issue?
Cookie cookie = new Cookie(); HttpWebRequest request = (HttpWebRequest) WebRequest.Create(<URL TO FETCH>); request.Credentials = CredentialCache.DefaultNetworkCredentials; // COMMENTED CODE INDICATES WE HAVE TRIED BUT HAVEN'T HAD ANY LUCK //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;