Asp.net mvc .NETCore3.0中是否有任何函数可以将url与其路由匹配

Asp.net mvc .NETCore3.0中是否有任何函数可以将url与其路由匹配,asp.net-mvc,routes,asp.net-core-3.0,Asp.net Mvc,Routes,Asp.net Core 3.0,我有一个包含URL的字符串,我想获得与此URL匹配的路由 假设URL字符串包含该值 http://localhost/PerformOperation/accountId/Operation/operationId 我有一个名为“PerformOperations”的路由,它与这个url匹配 PerformOperation/{accountId}/{action}/{operationId} 我怎么走这条路线?MVC显然在每个请求上都这样做,但我不知道如何手动完成。我有一个路由列表,我必须从U

我有一个包含URL的字符串,我想获得与此URL匹配的路由

假设URL字符串包含该值

http://localhost/PerformOperation/accountId/Operation/operationId

我有一个名为“PerformOperations”的路由,它与这个url匹配

PerformOperation/{accountId}/{action}/{operationId}

我怎么走这条路线?MVC显然在每个请求上都这样做,但我不知道如何手动完成。我有一个路由列表,我必须从URL中找到匹配的路由

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.UseEndpointRouting();

    //Your custom middleware that does something with routing data
    app.Use((context, next) =>
    {
    // let assume we are asking for http://localhost:18159/home/index/22
    var endpointFeature = context.Features[typeof(Microsoft.AspNetCore.Http.Features.IEndpointFeature)]
                                            as Microsoft.AspNetCore.Http.Features.IEndpointFeature;

    Endpoint endpoint = endpointFeature?.Endpoint;

    if (endpoint != null)
    {
        var routePattern = (endpoint as Microsoft.AspNetCore.Routing.RouteEndpoint)?.RoutePattern
                                                                                    ?.RawText;

        // Example result : Name: AdRaker.Core.Web.Tracker.Controllers.HomeController.Index (AdRaker.Core.Web.Tracker) 
        var info1 = $"Name: {endpoint.DisplayName}";
        // Example result: Route Pattern: Home/Index/{id?}
        var info2 = $"Route Pattern: {routePattern}";
        // Example result: Metadata Types: Microsoft.AspNetCore.Mvc.ControllerAttribute, 
        // Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor, Microsoft.AspNetCore.Routing.DataTokensMetadata, 
        // Microsoft.AspNetCore.Routing.RouteValuesAddressMetadata, Microsoft.AspNetCore.Mvc.Internal.ControllerActionFilter, 
        // Microsoft.AspNetCore.Mvc.ViewFeatures.SaveTempDataAttribute, Microsoft.AspNetCore.Mvc.ModelBinding.UnsupportedContentTypeFilter
        var info3 = $"Metadata Types: {string.Join(", ", endpoint.Metadata)}";
    }

    // Forward data to next middleware
    return next();
});
[...]

第一个中间件负责检查传入请求并将其与端点进行匹配。没有它,端点数据将始终为空

accountId
operationId
是实际值的占位符吗?我不知道有任何类似的内置方法。实际上,您必须引导整个路由框架并模拟通过的请求。你在这里的实际需要是什么?也许有更好的办法解决这个问题。