using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
HttpModule是过滤器,HttpHandler实现了ISAPI扩展功能,他处理请求(Request)的信息和发送响应(Response)。HttpHandler功能通过实行IHttpHandler接口达到。
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
HttpModule是过滤器,HttpHandler实现了ISAPI扩展功能,他处理请求(Request)的信息和发送响应(Response)。HttpHandler功能通过实行IHttpHandler接口达到。
HttpHandler处理程序实现了System.Web.IHttpHandler接口的.NET组件。任何事项了IHttpHandler接口的类都可以用于处理输入的HTTP请求,这类似于ISAPI扩展。HTTPHandler与ISAPI扩展的区别在于在URL中可以使用HttpHandler的文件名称直接调用,这与ISAPI扩展类似。
实现的步骤:
1、 编写类实现IHttphandler接口,并编译为dll
2、 在web.config或者machine.config文件中注册这个处理程序。
3、 在IIS中把文件扩展(你要处理的文件的扩展名)映射到ASP.NET ISAPI扩展 (aspnet_isapi.dll)上面。
4、建立一个*.xumh的文件,你会发现可以被处理了using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace xumh
{
/// <summary>
/// HttpHandler实现IHttpHandler接口,可以定义对特定类型的文件的处理
/// 1、编写类实现IHttpHandler接口,并编译为dll文件
/// 2、在web.config文件中注册
/// <httpHandlers>
/// <add verb="*" path="*.xumh" type="xumh.testHttpHandler,testHttpHandler"/>
/// <add verb="动作:Post/Get" path="处理的文件类型" type="空间.类名,dll名称"/>
/// </httpHandlers>
/// </summary>
public class testHttpHandler : IHttpHandler , System.Web.SessionState.IRequiresSessionState
{
/// <summary>
/// HttpHandler是否可以用于处理相同的其他类型的请求,实现重用
/// </summary>
public bool IsReusable
{
get { return true; }
}
/// <summary>
/// HttpHandler处理程序的核心,调用这个方法来处理Http请求
/// </summary>
/// <param name="context"></param>
public void ProcessRequest(HttpContext context)
{
string html = @"<html>
<body>
<h1>Hello xumh Reader</h1>
</body>
</html>";
//要处理session,必须引入System.Web.SessionState.IRequiresSessionState
System.Web.SessionState.HttpSessionState session = context.Session;
session["One"] = "Session One!";
//
context.Session["Another"] = "Another Session";
context.Response.Write("Session: Another 的值为 " + context.Session["Another"].ToString());
context.Response.Write(html);
}
}
}
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace xumh
{
/// <summary>
/// HttpHandler实现IHttpHandler接口,可以定义对特定类型的文件的处理
/// 1、编写类实现IHttpHandler接口,并编译为dll文件
/// 2、在web.config文件中注册
/// <httpHandlers>
/// <add verb="*" path="*.xumh" type="xumh.testHttpHandler,testHttpHandler"/>
/// <add verb="动作:Post/Get" path="处理的文件类型" type="空间.类名,dll名称"/>
/// </httpHandlers>
/// </summary>
public class testHttpHandler : IHttpHandler , System.Web.SessionState.IRequiresSessionState
{
/// <summary>
/// HttpHandler是否可以用于处理相同的其他类型的请求,实现重用
/// </summary>
public bool IsReusable
{
get { return true; }
}
/// <summary>
/// HttpHandler处理程序的核心,调用这个方法来处理Http请求
/// </summary>
/// <param name="context"></param>
public void ProcessRequest(HttpContext context)
{
string html = @"<html>
<body>
<h1>Hello xumh Reader</h1>
</body>
</html>";
//要处理session,必须引入System.Web.SessionState.IRequiresSessionState
System.Web.SessionState.HttpSessionState session = context.Session;
session["One"] = "Session One!";
//
context.Session["Another"] = "Another Session";
context.Response.Write("Session: Another 的值为 " + context.Session["Another"].ToString());
context.Response.Write(html);
}
}
}