我正在.NET 3.5下运行一个asp.net mvc 2站点,我想访问Global.asax中GetVaryByCustomString处理程序中的路由值。在传递给函数的HttpContext中,我不清楚如何(如果有的话)访问特定的路由值。

供参考,这是GetVaryByCustomString的签名

public override string GetVaryByCustomString(HttpContext context, string custom)
{
    // how do I get at route values here from context?
}


有人可以指出我正确的方向吗?

最佳答案

var routeData = ((MvcHandler)httpContext.Handler).RequestContext.RouteData;

var routeValues = routeData.Values;
var matchedRouteBase = routeData.Route;
var matchedRoute = matchedRouteBase as Route

关于asp.net - 如何在GetVaryByCustomString中访问ASP.NET MVC路由值?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7851374/

10-11 23:27
查看更多