当前位置:web 服务器 > IIS >>

用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执行后的结果

上一个:深度剖析Duwamish 7.0 (1--数据结构)
下一个:解决一个比较奇怪的NET问题的方法

Apache
IIS
Nginx
Tomcat
如果你遇到web 服务器难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,