Question

Im trying to upload a file to a webdav server but i get (401) Unauthorized. I cant figure out if my problem is with rights on the server or with my code? This is the code im using to test this:

string sourceFilePath = @"C:\testfile.txt";
string webAddress = "http://ip:port/";
string destinationFilePath = webAddress + "testfile.txt";

WebClient webClient = new WebClient();
webClient.UseDefaultCredentials = true;
webClient.UploadFile(destinationFilePath, "PUT", sourceFilePath);
webClient.Dispose();

However using the following code i can download files from the webdav server:

string webAddress = "http://ip:port/";
string sourceFilePath = webAddress + "testfile.txt";
string destinationFilePath = @"C:\testfile.txt";

WebClient webClient = new WebClient();            
webClient.UseDefaultCredentials = true;
webClient.DownloadFile(sourceFilePath, destinationFilePath);
webClient.Dispose();

The server is running iis 8 with webdav authoring rule configured. I have set full control for my user on the target folder at the server.

Edit: Realized that even if I remove the authoring rule i can download the file, why is this?

Authoring rule looks like this:

Was it helpful?

Solution

Installed and enabled windows authentication which solved the problem. Now that i think of it seems logic that it needs to be enabled...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top