发文章
发文工具
撰写
网文摘手
文档
视频
思维导图
随笔
相册
原创同步助手
其他工具
图片转文字
文件清理
AI助手
留言交流
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就可以了
来自: 昵称10504424 > 《工作》
0条评论
发表
请遵守用户 评论公约
IHttpModule和IHttpHandler 应用笔记
下面代码示例打印一行文字的WebApplication2.HelloHandler源码:using System;using System.Data;using System.Configuration;using System.Linq;using System.Web;using System.Web.Security;using Sy...
ASP.NET 自定义httpmodule于httphandler介绍
ASP.NET 自定义httpmodule于httphandler介绍。在这个事件之后,ASP.NET 把该请求转发给适当的HTTP处理程序 PostRequestHandlerExecute...
自定义处理程序
自定义处理程序。1.创建一个新类(calcHandler类),用于实现IHttpHandler接口。public void ProcessRequest(HttpContext cx) { ...
ASP.NET读取网络或本地图片显示
public class Handler : IHttpHandler { public void ProcessRequest (HttpContext context) { string imgUrl = context.public class Handler : IHttpHandler { public void Proc...
截获asp.net http输出流自己做处理,替换html内容_站长域名论坛www.91c...
tw_old = context.//Response原来的OutPut tw_new = new StringWriter(_content);//一个StringWriter,用来获取页面内容 var type_rp = context.Response.GetType(); tw_field = t...
一般处理程序
首先你发现 <%@ WebHandler Language="C#" Class="ImageHandler" %>这句话。<html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server&qu...
ASP.NET2.0 遍历文件夹下所有图片..
后台代码using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.U...
HttpHandler与HttpModule讲解
HttpHandler与HttpModule讲解HttpHandler对象必须实现IHttpHandler接口,在HttpApplication对象转交要求至HttpHandler对象时会调用此接...
关于asp.net中*.ashx类型的文件
关于asp.net中*.ashx类型的文件。首先,我们要回顾要使用ASHX文件的目标,我们要做的是在一个地址中用ASHX文件并动态的返回内容。开始:通过这几个步骤你可以添加一个新的ashx文件:打开你的ASP.NET we...
微信扫码,在手机上查看选中内容