about IHttpHandler
// Attempt to cast HttpHandler as a Page.
// HttpContext.Current :Get the HttpContext object for the current http request
// HttpContext. : self haven't other function ,only through the Current property to get the specific HttpContext
Page executingPage = HttpContext.Current.Handler as Page;
//HttpContext.Current.Handler return an IHttpHandler(System.Web.IHttpHandler which on duty to handl with the http Request获取一个值,该值指示其他请求是否可以使用 IHttpHandler 实例。
// Name this C# file HandlerTest.cs and compile it with the
// command line: csc /t:library /r:System.Web.dll HandlerTest.cs.
// Copy HandlerTest.dll to your \bin directory.
using System.Web;
namespace HandlerExample
{
public class MyHttpHandler : IHttpHandler
{
// Override the ProcessRequest method.
public void ProcessRequest(HttpContext context)
{
context.Response.Write("<H1>This is an HttpHandler Test.</H1>");
context.Response.Write("<p>Your Browser:</p>");
context.Response.Write("Type: " + context.Request.Browser.Type + "<br>");
context.Response.Write("Version: " + context.Request.Browser.Version);
}
// Override the IsReusable property.
public bool IsReusable
{
get { return true; }
}
}
}
/*
______________________________________________________________
To use this handler, include the following lines in a Web.config file.
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="handler.aspx" type="HandlerExample.MyHttpHandler,HandlerTest"/>
</httpHandlers>
</system.web>
</configuration>
*/本例中:客户端(浏览器)对handler.aspx的请求均由包含在程序集 HandlerTest.dll 中的命名空间 HandlerExample 中的 MyHttpHandler 类提供服务,所以尽管handler.aspx页面内没有内容,还是能在该页面被请求时显示内容,完全是HandlerTest.dll在处理浏览器对handler.aspx请求,HandlerTest.dll 决定了要返回给浏览器什么样的,什么内容。
事实上即使handler.aspx中有aspbutton等等也完全不会被理会,根本在浏览器中得不到显示。
本例中:
default.aspx中在浏览器端的“源代码”:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
zzz <div>
<hr />
<a id="HyperLink1" href="fold1/handler.aspx">redirect to handler.aspx</a>
</div>
</form>
</body>
</html>
****************************************************
而handler.aspx在浏览器端的源代码:
<H1>This is an HttpHandler Test.</H1><p>Your Browser:</p>Type: IE6<br>Version: 6.0
****************************************************
这样是不是会增加“效率”????
1.// Name this C# file HandlerTest.cs and compile it with the
// command line: csc /t:library /r:System.Web.dll HandlerTest.cs.
// Copy HandlerTest.dll to your \bin directory.
2.To use this handler, include the following lines in a Web.config file.
<configuration>
<system.web>
<httpHandlers>
<add verb="*" path="handler.aspx" type="HandlerExample.MyHttpHandler,HandlerTest"/>
</httpHandlers>
</system.web>
</configuration>
*/
testIHttpHandler


浙公网安备 33010602011771号