Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > HttpWebRequest Get

Reply
Thread Tools

HttpWebRequest Get

 
 
Jeremy Chapman
Guest
Posts: n/a
 
      11-26-2003
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;
}


 
Reply With Quote
 
 
 
 
John Timney \(Microsoft MVP\)
Guest
Posts: n/a
 
      11-26-2003
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;
> }
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get ubuntu ! Get ubuntu ! Get ubuntu ! Get ubuntu ! Getubuntu Windows 64bit 1 06-01-2009 08:54 AM
get image with httpwebrequest to stream to byte array to base64 =?Utf-8?B?RXNyZWYgRFVSTkE=?= ASP .Net 1 12-19-2004 09:43 AM
Issue with System.Net.HttpWebRequest Greg Reevosh via .NET 247 ASP .Net 0 10-31-2004 11:48 AM
Issue with System.Net.HttpWebRequest Greg Reevosh via .NET 247 ASP .Net 1 10-22-2004 06:21 PM
HttpWebResponse/HttpWebRequest problem... Satinderpal Singh ASP .Net 2 06-04-2004 04:40 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57