Hi Sousoux,
Welcome to MSDN newsgroup.
As for the HttpListener component in .net 2.0, it is just rely on the OS's
underlying http.sys kernal module to accept http requests... And for
Security authentication, it is done by the internal code which call
platform authentication apis to autheniticate the client request, and we
can not intercept the authentication progress... (just as we can not
intercept the IIS's authentication process when host our web application in
IIS server) If you want to do some customized athroization task based on
the authenticated client side user identity, you can get it through the
HttpListenerContext. e.g:
private void btnStart_Click(object sender, EventArgs e)
{
_httpsvc = new HttpListener();
string name = System.Environment.MachineName;
_httpsvc.Prefixes.Add("http://localhost:80/httpsvc/");
_httpsvc.Prefixes.Add("http://" + name + ":80/httpsvc/");
_httpsvc.AuthenticationSchemes =
AuthenticationSchemes.Negotiate;
_httpsvc.Start();
MessageBox.Show("http server started....");
IAsyncResult result = _httpsvc.BeginGetContext(new
AsyncCallback(ListenerCallback),_httpsvc);
MessageBox.Show("Waiting for request to be processed
asyncronously.");
}
private void btnStop_Click(object sender, EventArgs e)
{
_httpsvc.Stop();
MessageBox.Show("http server stoped....");
}
public static void ListenerCallback(IAsyncResult result)
{
HttpListener listener = (HttpListener)result.AsyncState;
HttpListenerContext context = listener.EndGetContext(result);
HttpListenerRequest request = context.Request;
HttpListenerResponse response = context.Response;
string responseString = "<HTML><BODY> Hello {0}!</BODY></HTML>";
responseString =
string.Format(responseString,context.User.Identity .Name);
byte[] buffer =
System.Text.Encoding.UTF8.GetBytes(responseString) ;
response.ContentLength64 = buffer.Length;
System.IO.Stream output = response.OutputStream;
output.Write(buffer, 0, buffer.Length);
// You must close the output stream.
output.Close();
}
The context.User.Identity just represent the authenticated client user
identity:
Hope helps.
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
Thread-Topic: Setting up HttpListener basic authentication
thread-index: AcYSwqU53vYU/iV5QAieWKg30xHFLQ==
X-WBNR-Posting-Host: 80.13.134.75
From: =?Utf-8?B?TWFydGlu?= <so*****@nospam.nospam>
Subject: Setting up HttpListener basic authentication
Date: Fri, 6 Jan 2006 05:11:03 -0800
Lines: 7
Message-ID: <35**********************************@microsoft.co m>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.framework.webservices
NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSF TNGXA03.phx.gbl
microsoft.public.dotnet.framework.webservices:1326 4
X-Tomcat-NG: microsoft.public.dotnet.framework.webservices
How does one set up basic authentication on an HttpListener? I know I need
to
set the HttpListener.AuthenticationSchemes to AuthenticationSchemes.Basic
but
then I'm unsure how and against what (users on the PC?) the Authentication
is
occuring. Is there a way for me to receive and control the Authentication
attempt myself?
This is probably obvious but I've found nothing describing it.