Home
Browse all 647 examples
Download all 647 examples
Download sample chapters
Reviews
Errata
Acknowledgments
Links on .NET
Paradoxal Press
Buy directly from Paradoxal Press at $33.99 (Save 43%)
Category: Programming
Level: Beginner to seasoned
900 pages
ISBN-10 097661322-0
ISBN-13 978-097661322-0
$59.99 USA
$79.99 CANADA
|
Listing 23-2 extracted from chapter ASP.NET 2
Listing 23-1< > Listing 23-3
This listing can be compiled with the command line: csc.exe /target:exe Example_23_2.cs /r:System.Web.dll Errors: 0 Warnings: 0
Example_23_2.cs
using System;
using System.Web;
using System.Web.Hosting;
using System.IO;
using System.Net;
class Program {
static void Main() {
CustomSimpleHost host = (CustomSimpleHost)
ApplicationHost.CreateApplicationHost(
typeof(CustomSimpleHost), @"/",
System.IO.Directory.GetCurrentDirectory());
HttpListener httpListener = new HttpListener();
string uri = string.Format("http://localhost:8008/");
httpListener.Prefixes.Add(uri);
httpListener.Start();
Console.WriteLine("Waiting on " + uri);
while (true) {
HttpListenerContext ctx = httpListener.GetContext();
string page = ctx.Request.Url.LocalPath.Replace("/", "");
string query = ctx.Request.Url.Query;
Console.WriteLine("Received request: {0}?{1}",page, query);
StreamWriter writer = new StreamWriter( ctx.Response.OutputStream,
System.Text.Encoding.Unicode);
host.ProcessRequest(page, query, writer);
writer.Flush();
writer.Close();
ctx.Response.Close();
}
}
}
public class CustomSimpleHost : MarshalByRefObject {
public void ProcessRequest(string file,string query,TextWriter writer) {
SimpleWorkerRequest aspnetWorker =
new SimpleWorkerRequest(file, query, writer);
HttpRuntime.ProcessRequest(aspnetWorker);
}
}
Copyright Patrick Smacchia 2006 2007
|