用C#实现无需iiS环境就可以执行aspx文件


myhost.cs 编译:
csc MyHost.cs /r:System.Web.dll

using System;
using System.IO;
using System.Web;
using System.Web.Hosting;


public class MyExeHost : MarshalByRefObject {

    public void ProcessRequest(String page)
        {
        HttpRuntime.ProcessRequest(new SimpleWorkerRequest(page, null, Console.Out));
        }

    public static void Main(String[] arguments)
        {
        MyExeHost host = (MyExeHost)ApplicationHost.CreateApplicationHost(typeof(MyExeHost), "/foo", Environment.CurrentDirectory);
           foreach (String page in arguments) {
            host.ProcessRequest(page);
        }
    }
}
test.ASPx
<HTML>
        <body>
                Time is now: <%=Now%>
        </body>
</HTML>
成功后就可以用下面的方法执行
MyHost.exe Test.ASPx > Test.htm
test.htm就是test.ASPx执行后的结果

本文作者:
« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3