I have an aspx-page in the Layouts-folder. A timejob makes a httpwebrequest on this page and the response-html is saved as a pdf. The httpwebrequest works fine, when its not called in a timerjob (ex. on another layouts-page), bbut when i execute the GetReponse()-Method in the timerjob i get an 401 (Unauthorized) error.
With this code it works in w3wp.exe
request.Method = "GET"; request.UseDefaultCredentials = true; request.PreAuthenticate = true; request.Credentials = CredentialCache.DefaultNetworkCredentials;
The only way i made it work in owstimer.exe is with
request.Credentials = new NetworkCredential(user, password, domain); HttpWebResponse response = (HttpWebResponse)request.GetResponse();
But we don't whant to store the passwort somewhere in plaintext.
How can i make it work in owstimer.exe without providing the credentials?