简体   繁体   English

在上传文件时出现401未经授权的错误

[英]Getting 401 Unauthorized error on file upload

I have an asp.net application that submits files to a sharepoint document library. 我有一个asp.net应用程序,它将文件提交到共享点文档库。 Each time it tries to submit I get a 每次尝试提交时,我都会得到一个

The remote server returned an error: (401) Unauthorized 远程服务器返回错误:(401)未经授权

Here is the c# code 这是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());
                    }                       

This works fine on my local machine, but when I deploy it to our test environment, it raises the 401 error. 这在我的本地计算机上运行良好,但是当我将其部署到测试环境中时,会引发401错误。 IIS is configured for anonymous authentication. IIS配置为匿名身份验证。 I think it is something to do with the file upload? 我认为这与文件上传有关? Any insight or thoughts are appreciated! 任何见解或想法都将受到赞赏!

Thanks 谢谢

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 应用程序更新程序-不断收到401未经授权的错误 - Application Updater - Keep getting 401 Unauthorized error 尝试上传文件时出现“远程服务器返回错误:(401)未经授权”错误 - “The remote server returned an error: (401) Unauthorized” error when trying to upload a file 将文件字节流发送到WCF服务时,为什么会出现“ 401-未经授权”错误? - Why am I getting a “401 - Unauthorized” error when sending a file byte stream to a WCF service? 为什么我会收到未经授权的Yahoo OAuth 2.0错误(401)? - Why i am getting Yahoo OAuth 2.0 error (401) Unauthorized? 为什么我在 Google Calendar API 中收到 (401) 未经授权的错误 - Why am I getting a (401) Unauthorized Error in Google Calendar API 尝试上传文件时出现401/403错误 - Getting 401 / 403 errors trying to upload a file ServiceBus引发401未经授权的错误 - ServiceBus throws 401 Unauthorized Error HttpWebResponse 401-error未经授权 - HttpWebResponse 401-error Unauthorized GCM提供错误:(401)未经授权 - GCM giving error: (401) Unauthorized WebClient 生成 (401) 未授权错误 - WebClient generates (401) Unauthorized error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM