1 using System; 2 using System.Web; 3 4 public class helloZZ : IHttpHandler { 5 6 public void PRocessRequest (HttpContext context) { 7 context.Response.ContentType = "text/plain"; 8 context.Response.Write("你请求的是hello.zz文件"); 9 }10 11 public bool IsReusable {12 get {13 return false;14 }15 }16 17 }
再在a目录下建立handler.ashx,代码如下:
<%@ WebHandler Language="C#" Class="MyHandler" %>using System;using System.Web;public class MyHandler : IHttpHandler { public void ProcessRequest (HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Write("Hello World"); } public bool IsReusable { get { return false; } }}
再建立如下的web.config
<?xml version="1.0"?><configuration> <system.web> <compilation debug="false" targetFramework="4.0" /> <httpHandlers> <add path="hello.zz" verb="*" type="helloZZ"/> </httpHandlers> </system.web></configuration>
特殊说明:
请直接用vs2012打开handler.ashx,右键用浏览器打开,这样做的只是为了构建一个web环境。再请求hello.zz就可以了
新闻热点
疑难解答