Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
    
Please elaborate: your want to avoid to have to provide the credential OR you want to avoid to store them in plain text? If the later suffice, I may have an idea. –  SPArchaeologist Apr 3 '13 at 12:44
    
if possible i want to avoid providing credentials, but if there isn't another way i'm open to your idea –  domueni Apr 3 '13 at 12:46
    
request.UseDefaultCredentials = true; should be sufficient, try it. –  Kai Apr 3 '13 at 13:02
    
Make sure that the code you're running is not making use of the SPContext or HttpContext as it wont exist in the timer job scope which might explain why the credentials need to be explicitly set. –  Grooverinthesouth Apr 3 '13 at 13:34
add comment

1 Answer 1

up vote 1 down vote accepted

Disclaimer: While this won't bypass the need to provide a set of user credential, at least will somehow avoid to store them as clear text.

The general idea is to use the Secure Store Service to store a set of credential that will be used in the request. You need to define an "app" and then access that application via codebehind from the timer job instance.

This sample from msdn should give you a quick start on the implementation. I have actually done this to provide site collection creation from a SPLongOperation context.

(note: I will add some more info/screens - have some network problem now. In the meantime free to ask further info as required)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.