Domanda

Ho una pagina ASPX nella cartella Layouts.Un timejob rende httpwebrequest in questa pagina e la risposta-HTML viene salvata come PDF. L'httpwebrequest funziona bene, quando non è chiamato in un timerjob (es. Su un altro layout-page), BBUT quando eseguo GetReponse () - Metodo nel Timerjob ottengo un errore 401 (non autorizzato).

Con questo codice funziona in w3wp.exe

request.Method = "GET";
request.UseDefaultCredentials = true;
request.PreAuthenticate = true;
request.Credentials = CredentialCache.DefaultNetworkCredentials;
.

L'unico modo in cui l'ho fatto funziona a OWstimer.exe è con

request.Credentials = new NetworkCredential(user, password, domain);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
.

Ma non possiamo sbannare per conservare il passwort da qualche parte in PLAINAMEXT.

Come posso farlo funzionare in OWstimer.exe senza fornire le credenziali?

È stato utile?

Soluzione

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)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top