不用IIS的网站
Code
1 using System;
2 using System.IO;
3 using System.Web;
4 using System.Web.Hosting;
5 using System.Net;
6
7 public class MyHost : MarshalByRefObject
8 {
9 public void ProcessRequest(string page, string query, TextWriter output)
10 {
11 SimpleWorkerRequest simple = new SimpleWorkerRequest(page, query, output);
12 HttpRuntime.ProcessRequest(simple);
13 }
14 }
15
16 public class Program
17 {
18 static void Main(string[] args)
19 {
20 MyHost host = (MyHost)ApplicationHost.CreateApplicationHost(typeof(MyHost), "/", @"D:\实验\TempCt\TempCt\bin\Debug");
21
22 if (HttpListener.IsSupported)
23 {
24 HttpListener listener = new HttpListener();
25 listener.Prefixes.Add("http://+:8080/");
26 listener.Start();
27
28 while (true)
29 {
30 HttpListenerContext context = listener.GetContext();
31
32 string page = context.Request.Url.LocalPath.Replace("/", "");
33 string query = context.Request.Url.Query.Replace("?", "");
34 Console.WriteLine("接收到请求:{0}?{1}", page, query);
35
36 StreamWriter sw = new StreamWriter(context.Response.OutputStream);
37 host.ProcessRequest(page, query, sw);
38 sw.Flush();
39 context.Response.Close();
40 }
41 }
42 Console.WriteLine("Press any key to exit");
43 Console.ReadKey(true);
44 }
45 }
1 using System;
2 using System.IO;
3 using System.Web;
4 using System.Web.Hosting;
5 using System.Net;
6
7 public class MyHost : MarshalByRefObject
8 {
9 public void ProcessRequest(string page, string query, TextWriter output)
10 {
11 SimpleWorkerRequest simple = new SimpleWorkerRequest(page, query, output);
12 HttpRuntime.ProcessRequest(simple);
13 }
14 }
15
16 public class Program
17 {
18 static void Main(string[] args)
19 {
20 MyHost host = (MyHost)ApplicationHost.CreateApplicationHost(typeof(MyHost), "/", @"D:\实验\TempCt\TempCt\bin\Debug");
21
22 if (HttpListener.IsSupported)
23 {
24 HttpListener listener = new HttpListener();
25 listener.Prefixes.Add("http://+:8080/");
26 listener.Start();
27
28 while (true)
29 {
30 HttpListenerContext context = listener.GetContext();
31
32 string page = context.Request.Url.LocalPath.Replace("/", "");
33 string query = context.Request.Url.Query.Replace("?", "");
34 Console.WriteLine("接收到请求:{0}?{1}", page, query);
35
36 StreamWriter sw = new StreamWriter(context.Response.OutputStream);
37 host.ProcessRequest(page, query, sw);
38 sw.Flush();
39 context.Response.Close();
40 }
41 }
42 Console.WriteLine("Press any key to exit");
43 Console.ReadKey(true);
44 }
45 }