在使用ASP.Net路由时,如何从代码隐藏中获取RouteData?
我知道您可以从RouteHandler的GetHttpHander方法中获得它(您将获得RequestContext),但是您能从代码隐藏中获得它吗?
有没有像这样的..。
RequestContext.Current.RouteData.Values["whatever"];您可以像使用HttpContext一样全局访问...that吗?
还是因为RouteData只能从RouteHandler内部访问?
发布于 2009-10-07 13:10:47
您可以使用以下内容:
RouteTable.Routes.GetRouteData(new HttpContextWrapper(HttpContext.Current));发布于 2011-05-12 18:48:58
您还可以使用以下代码:
//using System.Web;
HttpContext.Current.Request.RequestContext.RouteData发布于 2019-05-20 18:33:23
[HttpGet]
[Route("{countryname}/getcode/")]
public string CountryPhonecode()
{
// Get routdata by key, in our case it is countryname
var countryName = Request.GetRouteData().Values["countryname"].ToString();
// your method
return GetCountryCodeByName(string countryName);
}https://stackoverflow.com/questions/976855
复制相似问题