How to use Control.GetRouteUrl from a class in App_Code

后端 未结 1 674
无人共我
无人共我 2021-02-10 02:38

I\'m using routing in asp.net web forms 4.0 with some success. In my pages I am using Page.GetRouteURL to generate routes like this.



        
相关标签:
1条回答
  • 2021-02-10 03:34

    RequestContext is available as a property to HttpRequest object, so you can refer it as HttpContext.Current.Request.RequestContext. For example,

    public string GetRouteUrl(string routeName, object routeParameters)
    {
       var dict = new RouteValueDictionary(routeParameters);
        var data = RouteTable.Routes.GetVirtualPath(HttpContext.Current.Request.RequestContext, routeName, dict );
        if (data != null)
        {
            return data.VirtualPath;
        }
        return null;
    }
    
    0 讨论(0)
提交回复
热议问题