自定义路由注册,将URL路径映射到一个通用的处理程序ashx
使用Route和CustomRouteHandler
1.路由注册方法
public static void RegisterRoutes(RouteCollection routes) {}
2.配置路由规则
routes.Add(new Route(""),new CustomRouteHandler(""));
总结举例:
public static void RegisterRoutes(RouteCollection routes)
{
// 注册路由
routes.Add(new Route(
"v3/3rd/files/{file_id}", // 路径1
new CustomRouteHandler("~/Sample/FileHandler.ashx")
));
}
3.跳转FileHandler响应获取url中file_id数据
// 获取file_id参数
string fileId = context.Request.QueryString["file_id"];