step1:增加handler,继承IRouteHandler并实现接口
using MemberProductSite.Tools; using Nms.Common; using Nms.Common.Cryptography; using Nms.DBModel.MemberUserData; using System; using System.Linq; using System.Web; using System.Web.Routing; namespace MemberProductSite.AjaxHandler { /// <summary> /// MailVerify 继承IRouteHandler /// </summary> public class MailVerify : IHttpHandler, IRouteHandler { public void ProcessRequest(HttpContext context) { //获取参数 string encryptID = context.Request.RequestContext.RouteData.Values["eid"].ToString();
//自己的功能代码... } public IHttpHandler GetHttpHandler(RequestContext requestContext) {
//注意这里的写法 return this; } public bool IsReusable { get { return false; } } } }
step2:Global.asax(如果没有,新创建一个)中Application_Start注册路由
protected void Application_Start(object sender, EventArgs e) {
RegisterRoutes(RouteTable.Routes); } public static void RegisterRoutes(RouteCollection routes) {
//Route的第一个参数换成自己的路径 routes.Add(new Route("CheckMail/{eid}/{email}", new MailVerify())); }