How can I check if a route (ASP.NET MVC) exists for a given path? [duplicate]

旧时模样 提交于 2019-11-28 09:50:30

You can call RouteTable.Routes.GetRouteData with a mocked HttpContextBase.

The routes are matched internally using the request's AppRelativeCurrentExecutionFilePath.
However, this functionality is not exposed, so you need to pass an HttpContextBase.

You need to create an HttpContextBase class which returns an HttpRequestBase instance in its request property.
The HttpRequestBase class needs to return your path, beginning with ~/, in its AppRelativeCurrentExecutionFilePath property.

You don't need to implement any other properties, unless they're used by IRouteConstraints.

To check whether you got an MVC route, check whether the resulting routeData.Handler is MvcRouteHandler.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!