J
Jeremy Chapman
In IIS, I've got an application directory called AuthenticationTest. I've
also got an app directory called TestWinAuth.
Both are under the wwwroot directory.
My AuthenticationTest app enables anonymous access, while the TestWinAuth
app uses windows authentication. I have 1 file in my TestWinAuth directory
called test.html
In my AuthenticationTest app, I have the following code which does an HTTP
Get on the file in the TestWinAuth directory. I thought that this would
issue a challange response and attempt to authenticate me using windows
authentication, but I just get an error 401 message. If I go to the link
directly though I get authenticated. Is there any way to get the
authentication to work?
try
{
Label2.Text = http://MyServerName/TestWinAuth/test.html";
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(Label2.Text);
// Define the request access method.
req.Method = "GET";
HttpWebResponse result = (HttpWebResponse) req.GetResponse();
Label1.Text = "passed";
}
catch (WebException we)
{
// Display any errors. In particular, display any protocol-related
error.
if (we.Status == WebExceptionStatus.ProtocolError)
{
HttpWebResponse hresp = (HttpWebResponse) we.Response;
Label1.Text = "Authentication Failed, " + hresp.StatusCode + "\r\n"
+
"Status Code: " + (int) hresp.StatusCode + "\r\n" +
"Status Description: " + hresp.StatusDescription;
}
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}
also got an app directory called TestWinAuth.
Both are under the wwwroot directory.
My AuthenticationTest app enables anonymous access, while the TestWinAuth
app uses windows authentication. I have 1 file in my TestWinAuth directory
called test.html
In my AuthenticationTest app, I have the following code which does an HTTP
Get on the file in the TestWinAuth directory. I thought that this would
issue a challange response and attempt to authenticate me using windows
authentication, but I just get an error 401 message. If I go to the link
directly though I get authenticated. Is there any way to get the
authentication to work?
try
{
Label2.Text = http://MyServerName/TestWinAuth/test.html";
HttpWebRequest req = (HttpWebRequest) WebRequest.Create(Label2.Text);
// Define the request access method.
req.Method = "GET";
HttpWebResponse result = (HttpWebResponse) req.GetResponse();
Label1.Text = "passed";
}
catch (WebException we)
{
// Display any errors. In particular, display any protocol-related
error.
if (we.Status == WebExceptionStatus.ProtocolError)
{
HttpWebResponse hresp = (HttpWebResponse) we.Response;
Label1.Text = "Authentication Failed, " + hresp.StatusCode + "\r\n"
+
"Status Code: " + (int) hresp.StatusCode + "\r\n" +
"Status Description: " + hresp.StatusDescription;
}
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}