编程语言
首页 > 编程语言> > asp.net 路由映射到ashx

asp.net 路由映射到ashx

作者:互联网

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())); }

 

标签:asp,MailVerify,void,System,IRouteHandler,ashx,using,net,public
来源: https://www.cnblogs.com/shihao316558512/p/12930268.html