- using System;
- using System.IO;
- using System.Web;
- using System.Web.Hosting;
- using System.Net;
- public class MyHost : MarshalByRefObject
- {
- public void ProcessRequest(string page, string query, TextWriter output)
- {
- SimpleWorkerRequest simple = new SimpleWorkerRequest(page, query, output);
- HttpRuntime.ProcessRequest(simple);
- }
- }
- public class Program
- {
- static void Main(string[] args)
- {
- MyHost host = (MyHost)ApplicationHost.CreateApplicationHost(typeof(MyHost), "/", @"D:/实验/TempCt/TempCt/bin/Debug");
- if (HttpListener.IsSupported)
- {
- HttpListener listener = new HttpListener();
- listener.Prefixes.Add("http://+:8080/");
- listener.Start();
- while (true)
- {
- HttpListenerContext context = listener.GetContext();
- string page = context.Request.Url.LocalPath.Replace("/", "");
- string query = context.Request.Url.Query.Replace("?", "");
- Console.WriteLine("接收到请求:{0}?{1}", page, query);
- StreamWriter sw = new StreamWriter(context.Response.OutputStream);
- host.ProcessRequest(page, query, sw);
- sw.Flush();
- context.Response.Close();
- }
- }
- Console.WriteLine("Press any key to exit...");
- Console.ReadKey(true);
- }
- }
不用IIS的网站
最新推荐文章于 2021-10-17 18:06:35 发布