ASP.NET页面生命周期之HttpHandler
单个handler
namespace TestForWeb { public class MyHandler : IHttpHandler { public bool IsReusable { get { return false; } } public void ProcessRequest(HttpContext context) { context.Response.Write("hehe"); } } }
handler工厂
namespace TestForWeb { public class MyHandlerFactory:IHttpHandlerFactory { public IHttpHandler GetHandler(HttpContext context, string requestType, string url, string pathTranslated) { if (url.Contains("1")) { return new Handler1(); } else { return new Handler2(); } } public void ReleaseHandler(IHttpHandler handler) { } } public class Handler1:IHttpHandler { public bool IsReusable { get { return true; } } public void ProcessRequest(HttpContext context) { context.Response.Write("1"); } } public class Handler2 : IHttpHandler { public bool IsReusable { get { return true; } } public void ProcessRequest(HttpContext context) { context.Response.Write("2"); } } }
集成模式才会这么用
<system.webServer>
<modules>
<add name="MyModule" type="TestForWeb.MyModule,TestForWeb" />
</modules>
<handlers>
<add name="MyHandlerFactory" path="*.ds" verb="*" type="TestForWeb.MyHandlerFactory,TestForWeb" />
</handlers>
</system.webServer>
浙公网安备 33010602011771号