When you use your browser you are being identified - possibly via something
called passthrough authentication (you didn't say if you get challenged).
Anyway, when you make a call from the web classes you have to tell it who to
make the call as as explained here
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemnethttpwebrequestclasscredentialstopic. asp
--
Regards
John Timney (Microsoft ASP.NET MVP)
----------------------------------------------
<shameless_author_plug>
Professional .NET for Java Developers with C#
ISBN:1-861007-91-4
Professional Windows Forms
ISBN: 1861005547
Professional JSP 2nd Edition
ISBN: 1861004958
Professional JSP
ISBN: 1861003625
Beginning JSP Web Development
ISBN: 1861002092
</shameless_author_plug>
----------------------------------------------
"Jeremy Chapman" <> wrote in message
news:...
> 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;
> }
>
>