0

我有一个将文件提交到共享点文档库的 asp.net 应用程序。每次它尝试提交时,我都会得到一个

远程服务器返回错误:(401) Unauthorized

这是c#代码

                    byte[] buffer = new byte[length];
                    postedFile.InputStream.Read(buffer, 0, length);


                    Uri address = new Uri(url);
                    HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
                    request.Method = "POST";

                    request.UseDefaultCredentials = true;

                    request.Accept = "application/json;odata=verbose";
                    request.Headers.Add("X-RequestDigest", dvalue);
                    request.ContentType = "application/json; charset=utf-8";
                    request.ContentLength = length;
                    using (Stream postSTream = request.GetRequestStream())
                    {
                        postSTream.Write(buffer, 0, length);
                    }
                    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                    {
                        StreamReader reader = new StreamReader(response.GetResponseStream());
                    }                       

这在我的本地机器上运行良好,但是当我将它部署到我们的测试环境时,它会引发 401 错误。IIS 配置为匿名身份验证。我认为这与文件上传有关?任何见解或想法表示赞赏!

谢谢

4

1 回答 1

0

您应该为应用程序池用户帐户授予写入文件夹权限。

于 2013-10-08T05:45:29.737 回答