开发者

How do I use AppPool credentials?

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);

d开发者_Go百科ocumentName = Path.GetFileName(reference);

return new FileStreamResult(fileInformation.Stream, contentType)
{
  FileDownloadName = documentName
};


Check out this question:

Getting NetworkCredential for current user (C#)

If you can just get the client context to use the credentials of the process that is running it then you will be using the credentials of the application pool. It might use the current user context by default if you don't provide any credentials.

You will need to be sure that the application pool credentials have access to the file as well. You can configure the application pool user in IIS under advanced settings of the application pool and choose a user that has access to the share point files.

If you are just running in the context of visual studio then the current logged in user will be set to the default credentials.


According to MSDN, "the Client Object Model automatically uses the default credentials." Have you tried not setting the credentials on the client context? The following is also shown at the same link:

context.Credentials = CredentialCache.DefaultCredentials;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜