Esempio n. 1
0
        /// <summary>
        /// Set action url.
        /// </summary>
        /// <param name="urlHelper"></param>
        /// <param name="areaInfoList"></param>
        /// <param name="apiRouteName"></param>
        /// <returns></returns>
        private static List <AreaInfo> SetUrlValue(UrlManager urlHelper, List <AreaInfo> areaInfoList, string apiRouteName)
        {
            foreach (var ai in areaInfoList)
            {
                foreach (var ci in ai.ControllerInfoCol)
                {
                    foreach (var aig in ci.ActionInfoCol)
                    {
                        foreach (var sig in aig.Signatures)
                        {
                            object dic;

                            if (sig.IsApiController)
                            {
                                if (string.IsNullOrWhiteSpace(sig.Area) == false)
                                {
                                    dic = new { area = sig.Area, httproute = "", controller = sig.Controller, action = sig.Action };
                                }
                                else
                                {
                                    dic = new { httproute = "", controller = sig.Controller, action = sig.Action };
                                }

                                sig.Url = urlHelper.RouteUrl(apiRouteName, dic);
                            }
                            else
                            {
                                if (string.IsNullOrWhiteSpace(sig.Area) == false)
                                {
                                    dic = new { area = sig.Area };
                                }
                                else
                                {
                                    dic = new { };
                                }

                                sig.Url = urlHelper.Action(sig.Action, sig.Controller, dic);
                            }

                            if (sig.Url != null && sig.Url.Contains('?'))
                            {
                                //ex: if routeTemplate = "api/{controller}/{id}", url_temp = "/Person?action='PostName'"
                                //ex: we remove the query string.
                                sig.Url = sig.Url.Split('?')[0];
                            }
                        }
                    }
                }
            }

            return(areaInfoList);
        }