[英]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.