473,395 Members | 1,411 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.

TCPClient connect to IIS 6 with Integrated Windows Authentication

I've written a simple web stress tester application using TCPClient.
My code was working fine against our web server until our server admin changed IIS security setting by removing anonymous access and adding Integrated windows authentication.
Now I get 401 Unauthorized errors.
Here is the code that was working:
Expand|Select|Wrap|Line Numbers
  1. // Make non-secure HTTP Client connections.
  2.         private string MakeTcpClientRequest()
  3.         {
  4.             String _url = this.SiteUrl;
  5.             String _path = this.SitePath;
  6.             String _domain = this.SiteDomain;
  7.             IPAddress _ip = this.SiteIpAddress;
  8.             Int32 _port = this.SitePort;
  9.  
  10.             String response = string.Empty;
  11.  
  12.             try
  13.             {
  14.                 TcpClient client = new TcpClient();
  15.                 client.Connect(_domain, _port);
  16.                 client.LingerState = (new LingerOption(true, 0));
  17.  
  18.                 //Console.WriteLine("Client Connected.");
  19.                 string crlf = Environment.NewLine;
  20.  
  21.                 NetworkStream stream = client.GetStream();
  22.  
  23.                 UTF8Encoding encoder = new UTF8Encoding();
  24.                 String pageString = "GET " + _path + " HTTP/1.1" + crlf;
  25.                 pageString += "Accept:*.*" + crlf;
  26.                 pageString += "HOST: " + _domain + ":" + _port + crlf + crlf;
  27.  
  28.                 byte[] send = encoder.GetBytes(pageString);
  29.  
  30.                 if (stream.CanWrite)
  31.                 {
  32.                     stream.Write(send, 0, send.Length);
  33.                     stream.Flush();
  34.                 }
  35.                 else
  36.                 {
  37.                     throw new Exception("NetworkStream cannot write data.");
  38.                 }
  39.  
  40.                 using (StreamReader reader = new StreamReader(stream, true))
  41.                 {
  42.                     response = reader.ReadLine();
  43.                 }
  44.  
  45.                 stream.Close();
  46.                 client.Close();
  47.             }
  48.             catch (SocketException ex)
  49.             {
  50.                 //throw ex;
  51.                 Console.WriteLine(ex.ToString());
  52.             }
  53.             catch (Exception ex)
  54.             {
  55.                 //throw ex;
  56.                 Console.WriteLine(ex.ToString());
  57.             }
  58.             // Set the response code:
  59.             this._responseCode = (HttpStatusCode)SetResponseCode(response);
  60.  
  61.             return response;
  62.         }
  63.  
I'm not really sure where to go from here and was hoping someone could point me in the right direction.
Much thanks in advance.

-Matt
Jun 9 '09 #1
1 3235
Plater
7,872 Expert 4TB
There exists an HttpWebRequest object that would do this functionality for you.
You will need to supply credentials, either in the header via a string like you are using now, or in the HttpWebRequest object
Jun 10 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jim | last post by:
I'm working on my first .net project using c#. I've been using activex controls embedded in a web page and wanted to do the same in ..net. My approach has been to create a windows control library...
1
by: Jim Bunton | last post by:
Win 2000, sqlServer 2000 Personal edition Trying ot connect using .asp Vb Script 1. Sql server set to use Windows Authentication 2. Log onto Windows 2000 as Jim Bunton {no password) 3 Server...
9
by: Tom B | last post by:
In my web.config file I've specified Windows for the authentication, in IIS I've set it to Integrated Authentication. But my SQL connection is still showing Anonymous. Is there somewhere else I...
7
by: Reza | last post by:
Hello The project was working, where I had a domain user registered in the database as a user, and I used that user to connect the datebase. Everything was fine and it was working, then when I...
4
by: Andrew | last post by:
Hey all, I would like to preface my question by stating I am still learning ASP.net and while I am confident in the basics and foundation, the more advanced stuff is still a challenge. Ok....
3
by: Patrick.O.Ige | last post by:
Hi folks, How can i pass credentials to windows integrated authentication. I want to use my credentials from windows authentication and pass it on to different asp.net and asp pages without having...
2
by: Amedee Van Gasse | last post by:
Hello, Since it is the first time I'm posting in these groups, I believe a (short) introduction of myself would not be a bad thing. I am mainly a support engineer, not a programmer. I do have...
0
by: jordo | last post by:
I have an asp.Net app that connects to the WSS 2.0 list web service. I'm having issues with IIS and .Net configurations and hope that someone can help me. My ideal configuration is: asp.net:...
11
by: benoitc | last post by:
I've been having a problem debugging an ASP.NET 1.1 application on an existing Windows XP/Visual Studio 2003 workstation that I've inherited from somebody else. The application builds fine, but...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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.