如何使用 AppPool 凭据?
我们的网络应用程序能够从 Sharepoint 下载文件并将其呈现给用户,但前提是我向该过程提供我的个人用户名和密码。我收到一条建议:我们“应该使用 AppPool 的凭据 (UseDefaultCredentials=True.
)”,
我需要进行哪些更改才能使其与 UseDefaultCredentials=True
一起使用?什么是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
};
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
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看这个问题:
获取当前用户的 NetworkCredential (C#)
如果可以只需让客户端上下文使用正在运行它的进程的凭据,那么您将使用应用程序池的凭据。如果您不提供任何凭据,它可能会默认使用当前用户上下文。
您需要确保应用程序池凭据也有权访问该文件。您可以在 IIS 中的应用程序池高级设置下配置应用程序池用户,并选择有权访问共享点文件的用户。
如果您只是在 Visual Studio 上下文中运行,则当前登录的用户将设置为默认凭据。
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.
根据 MSDN,“客户端对象模型自动使用默认凭据。” 您是否尝试过不在客户端上下文中设置凭据?以下内容也显示在同一链接中:
context.Credentials = CredentialCache.DefaultCredentials;
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;