Our webapp is able to download files from Sharepoint and surface them to the user, but only if I provide my personal username and password to the process. I received a suggestion that: we "should use the credentials of the AppPool (UseDefaultCredentials=True.
)"
What changes do I make to for this to work with UseDefaultCredentials=True
? And what is UseDefaultCredentials=true
?
string documentName = null;
string contentType = "unknown";
// We don't want to use this method of credentials
System.Net.NetworkCredential cred = new System.Net.NetworkCredential("USERNAME", "PASSWORD");
ClientContext clientContext = new ClientContext("http://MOSSSERVER/MYDIRECTORY");
clientContext.Credentials = cred;
FileInformation fileInformation = Microsoft.SharePoint.Client.File.OpenBinaryDirect(clientContext, reference);
documentName = Path.GetFileName(reference);
return new FileStreamResult(fileInformation.Stream, contentType)
{
FileDownloadName = documentName
};