Ashx 文件
Ashx文件就是一个web handler文件,可以添加这个文件,加上web.config的配置来实现map url ,即把请求路由到 handler中来处理
1、添加一个handler.ashx
2、配置web.config
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<urlMappings enabled="true">
<add url="~/default.aspx" mappedUrl="~/Handler.ashx"/>
</urlMappings>
</system.web>
3、handler,添加handler会生成默认的测试代码:
public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
}
public bool IsReusable {
get {
return false;
}
}
}
4、直接运行,
http://localhost:1982/web/default.aspx
会输出:
hello world