C# 如何将自定义aspx页面重定向到mvc操作方法

C# 如何将自定义aspx页面重定向到mvc操作方法,c#,asp.net,asp.net-mvc,routing,nopcommerce,C#,Asp.net,Asp.net Mvc,Routing,Nopcommerce,我已将aspx项目升级到mvc。现在,我的一些老客户使用.aspx页面调用url,他们在mvc项目中得到了404(未找到) 所以现在我必须将.aspx重定向到mvc页面 旧网址 www.domain.com/bookshop/showproduct.aspx?isbn=978-1-59333-934-0 新网址 www.domain.com/{product_name} 我想通过mvc的路由机制来做。就像这种类型的url出现后,它应该调用我的自定义mvc操作,在字符串参数中,我将获得show

我已将aspx项目升级到mvc。现在,我的一些老客户使用.aspx页面调用url,他们在mvc项目中得到了404(未找到)

所以现在我必须将.aspx重定向到mvc页面

旧网址

www.domain.com/bookshop/showproduct.aspx?isbn=978-1-59333-934-0
新网址

www.domain.com/{product_name}
我想通过mvc的路由机制来做。就像这种类型的url出现后,它应该调用我的自定义mvc操作,在字符串参数中,我将获得showproduct.aspx?isbn=978-1-59333-934-0


您能否建议一种使用最少代码的最佳方法。

创建一个新的类RouteHandler,如下所示:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Routing;

namespace Sample.Helpers
{
    public class RouteHandler : IRouteHandler
    {
        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            return new ASPDotNetHttpHandler();
        }
    }

    public class ASPDotNetHttpHandler : IHttpHandler
    {
        public bool IsReusable
        {
            get
            {
                return true;
            }
        }

        public void ProcessRequest(HttpContext context)
        {
            string product = context.Request.QueryString["isbn"];
            int index = context.Request.Url.AbsoluteUri.IndexOf("bookshop/showproduct.aspx?");

            if (!(string.IsNullOrEmpty(product) || index == -1))
            {
                string newUrl = context.Request.Url.AbsoluteUri.Substring(0, index)+"/" + product;
                context.Response.Redirect(newUrl, true);
            }
        }
    }
}
在RouteConfig.cs文件的RegisterRoutes方法中插入新路由,如下所示:

    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.Add(new Route("bookshop/showproduct.aspx", new BIRS.Web.Helpers.RouteHandler()));