C# 不使用密码将文件上载到sharepoint

C# 不使用密码将文件上载到sharepoint,c#,.net,iis,sharepoint,sharepoint-2010,C#,.net,Iis,Sharepoint,Sharepoint 2010,我正在尝试使用microsoft sharepoint客户端使用c将文件上载到sharepoint 当我创建我的上下文并像这样给它我的用户名和密码时,我没有任何问题 using (ClientContext ctx = new ClientContext(spSite)) { if (!System.IO.File.Exists(fileLocation))

我正在尝试使用microsoft sharepoint客户端使用c将文件上载到sharepoint

当我创建我的上下文并像这样给它我的用户名和密码时,我没有任何问题

                using (ClientContext ctx = new ClientContext(spSite))
                {

                    if (!System.IO.File.Exists(fileLocation))
                        throw new FileNotFoundException("File not found.", fileLocation);

                    var credentials = new NetworkCredential("username", "password");
                    ctx.Credentials = credentials;
                    Web web = ctx.Web;

                    ctx.Load(user);
                    ctx.ExecuteQuery();
                    String fileName = System.IO.Path.GetFileName(fileLocation);
                    FileStream fileStream = System.IO.File.OpenRead(fileLocation);

                    ctx.Load(web.Folders);
                    ctx.ExecuteQuery();
                    Folder spFolder = web.Folders.FirstOrDefault(x => x.Name.Equals(spListCleanName));

                    FileCreationInformation fci = new FileCreationInformation();
                    fci.Url = spSite + spLibraryName + file;



                    byte[] bytes = System.IO.File.ReadAllBytes(fileLocation);
                    fci.Content = bytes;

                    Microsoft.SharePoint.Client.File spFile = spFolder.Files.Add(fci);
                    spFile.ListItemAllFields.Update();
                    ctx.ExecuteQuery();

                }
但我的问题来自网络认证部分。是否有办法通过iis或.net或其他方式使用当前用户的凭据,以便我不必询问他们的密码?因为这不是我们想要保存在任何地方的纯文本


提前感谢

使用CredentialCache.DefaultCredentials而不是NetworkCredential对象


这将使用用户安全上下文。

ASP.NET允许您使用Windows集成身份验证来实现SSO。我将如何使用它?我尝试使用HttpClientHandler并将默认凭据设置为true,但当我尝试将其设置为我的ctx对象时,它是null的,请看一下的文档;你需要将身份验证模式设置为Windows。是的,它实际上设置为Windows。如果是IIS express而不是普通IIS,这有关系吗?因为它还没有给我证件谢谢你的建议。似乎它只适用于NTLM、摘要、Kerberos和协商身份验证类型,实际上我需要的是windows。当我检查凭证时,它们是空的