不用IIS的网站

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值