I got a server with Apache running. Now I want to be able to read the contents of a folder there and for that this folder is configured in the Apache httpd.conf something like this:
Alias /folder "E:/Folder"
<Directory "E:/Folder">
AuthName "Public Folder"
AuthType SSPI
SSPIAuth On
SSPIAuthoritative On
SSPIDomain DOMAIN
SSPIOfferBasic On
SSPIOfferSSPI On
SSPIBasicPreferred Off
SSPIOmitDomain On
SSPIUsernameCase lower
require group "DOMAIN\Domain Users"
</Directory>
Now when I use a Browser I can already access this Information with the URL http://ServerName/Folder/
So this workes just fine already. But now I am trying to receive this Folder-Data for my C# application. I am using DefaultNetworkCredentials and my Code looks something like this:
public void CheckFolder()
{
WebRequest request = HttpWebRequest.Create(_uri);
request.Credentials = CredentialCache.DefaultNetworkCredentials;
request.BeginGetResponse(new AsyncCallback(HandleGetAvailableUpdates), request);
}
void HandleGetAvailableUpdates(IAsyncResult state)
{
try
{
if (state.IsCompleted)
{
WebRequest req = state.AsyncState as WebRequest;
WebResponse response = req.EndGetResponse(state);
Stream wStream = null;
wStream = response.GetResponseStream();
byte[] data = new byte[response.ContentLength];
etc.
.
.
.
}
catch (WebException ex)
{
Console.WriteLine(ex.ToString());
}
}
}
req.EndGetResponse(state) now throws the WebException:
The remote server returned an error: (401) Unauthorized.
Going back on Server-Side I have a look at the Apache error.log and there I find:
(OS 87)The parameter is incorrect. : authentication failure for "/folder": user unknown, reason: cannot generate context
This feature of the Program already worked well about two month ago. The C#-Code did not change at all but I dont know if something had been done with the server or the Apache configuration. I also tried to give my Credentials (username and pw, the same I use when acces开发者_C百科sing via Web-Browser) manually in the C#-Code rather than using the DefaultNetworkCredentials but with no avail. So finally my question would be: Is there something I forgot? Are there any other settings on the server to be made to make it work?
Easiest way to find out: User Fiddler, or Live Http Headers, or any other HTTP packet sniffer to see which headers/post parameters are sent by the browser, and then duplicate all of them programatically.
精彩评论