473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

HttpWebRequest Get

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;
}
Nov 18 '05 #1
1 2951
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" <No****@Please.com> wrote in message
news:ex*************@TK2MSFTNGP10.phx.gbl...
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;
}

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Dan Battagin | last post by:
Is there a known bug with the interaction between the HttpWebRequest and the ThreadPool? I current spawn several HttpWebRequest's using BeginGetResponse, and they work for a while, using worker...
10
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is...
9
by: Mike Cronin via DotNetMonster.com | last post by:
Hi there, Can anyone tell me what level of encryption is used when making an HTTPS POST request through an instance of the System.Net.HttpWebRequest object? Thanks much in advance! Mike...
16
by: thomas peter | last post by:
I am building a precache engine... one that request over 100 pages on an remote server to cache them remotely... can i use the HttpWebRequest and WebResponse classes for this? or must i use the...
1
by: sfoxover | last post by:
Hi, Could someone please give me some suggestions on how to make this class robust. I need to be able to handle around 20 similtanious requests to this class which causes a web browser to...
6
by: Mike Koerner | last post by:
Hi, I am having problems setting the HttpWebRequest Date header. I understand that it is a restricted header and I do receive the "This header must be modified with the appropriate property." ...
16
by: Cheung, Jeffrey Jing-Yen | last post by:
I have a windows form application that generates a request, downloads an image, and waits the user to enter in login info. Unfortunately, this image is dynamic and based on session data. I have...
0
by: boxboy | last post by:
Hi, I'm writing a console application and am having a problem with HttpWebRequest when posting data to a webserver. A "System.Net.WebException: The server committed a protocol violation" is always...
3
by: JansenH | last post by:
We have implemented a 'HTTP Post' client in C# that posts Xml documents to a webserver. This is working fine if the post rate is one post for every 20 seconds. But if the post rate is increased to...
1
by: Proogeren | last post by:
I have a problem with a httpwebrequest that I am creating. The request in itself looks correct but using fiddler I see that a www-authentication header is sent along as well. The code is pasted...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.