将 ASPX 页面编译成 DLL

来源:互联网 发布:java邮件开发 编辑:程序博客网 时间:2024/04/29 15:34
  • 定义由System.Web.IHttpHandler接口派生的自定义类。实现接口中的IsReusableProcessRequest(HttpContext ctxt)成员

    using System.Web;using System;namespace StoT{//===============//start namespace//===============public class Index : IHttpHandler{public bool IsReusable{get{return true;}}public void ProcessRequest(HttpContext ctxt){HttpRequest rq = ctxt.Request;HttpResponse rp = ctxt.Response;HttpServerUtility sv = ctxt.Server;...sv=null;rp=null;rq=null;}}//=============//end namespace//=============}
  • 编译自定义类并输出为StoTIndex.dll文件,把它拷贝至/bin目录下
  • 在web.config配置文件中配置对自定义名字空间和类的引用

    <?xmlversion="1.0"?><configuration><system.web><globalizationfileEncoding="gb2312"requestEncoding="gb2312"responseEncoding="gb2312"/><httpHandlers><addverb="*"path="/stot/index.aspx"type="StoT.Index, StoTIndex"/></httpHandlers><customErrorsmode="Off"defaultRedirect="/"></customErrors></system.web></configuration>
  • 这样,凡是对/stot/index.aspx的请求都会由自定义的DLL文件来进行处理了,性能可以提升不少。
 
原创粉丝点击