首页 > 网站 > IIS > 正文

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

2024-08-29 03:13:55
字体:
来源:转载
供稿:网友

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执行后的结果
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表