Forum How do I...?

warning: The requested URL returned error: 401 Unauthorized

paul.rebelo
I'm getting a warning: The requested URL returned error: 401 Unauthorized in the log file for a bunch of style sheets and images.

I'm attempting to run prince over an ASP.Net page (.aspx) from within SharePoint. The code is running in elevated privileges (farm account) so I don't understand the warning.
It's still producing an output but not the result I was hoping for.

code snippet
SPSecurity.RunWithElevatedPrivileges(delegate () {
WebRequest request = WebRequest.Create(currentPage);
request.Credentials = CredentialCache.DefaultNetworkCredentials;
WebResponse response = request.GetResponse();
using (stream = response.GetResponseStream())
{
Response.ContentType = "application/pdf";
prn.SetHTML(true);
prn.SetBaseURL(SPContext.Current.Site.Url);
prn.AddStyleSheet(cssFileName);
prn.Convert(stream, Response.OutputStream);
}
response.Close();
});
mikeday
The privileges that your ASP.NET page has will not be passed to the separate Prince executable when it makes requests for images and style sheets. Currently you can specify authentication options via the Prince wrapper; perhaps in future we can provide a method to take the request credentials directly.