Beispiel #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="urlHelper"></param>
 /// <param name="actionName"></param>
 /// <param name="controllerName"></param>
 /// <param name="routeValues"></param>
 /// <param name="requireAbsoluteUrl"></param>
 /// <returns></returns>
 public static string Action(this UrlHelper urlHelper, string actionName, string controllerName, RouteValueDictionary routeValues, bool requireAbsoluteUrl)
 {
     if (requireAbsoluteUrl)
     {
         RouteBase   route       = RouteTable.Routes.GetVirtualPath(_GetRequestContext(urlHelper, controllerName, actionName), routeValues).Route;
         DomainRoute domainRoute = route as DomainRoute;
         if (domainRoute != null)
         {
             DomainData domain    = domainRoute.GetDomainData(urlHelper.RequestContext, routeValues);
             string     urlString = urlHelper.Action(actionName, controllerName, routeValues, domain.Protocol, domain.Host);
             return(Regex.Replace(urlString, @"\:\d+", domain.Port > 0 ? ":" + domain.Port : string.Empty));
         }
     }
     return(urlHelper.Action(actionName, controllerName, routeValues));
 }
Beispiel #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="htmlHelper"></param>
 /// <param name="linkText"></param>
 /// <param name="actionName"></param>
 /// <param name="controllerName"></param>
 /// <param name="routeValues"></param>
 /// <param name="htmlAttributes"></param>
 /// <param name="requireAbsoluteUrl"></param>
 /// <returns></returns>
 public static MvcHtmlString ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, RouteValueDictionary routeValues, IDictionary <string, object> htmlAttributes, bool requireAbsoluteUrl)
 {
     if (requireAbsoluteUrl)
     {
         HttpContextBase currentContext = new HttpContextWrapper(HttpContext.Current);
         RouteData       routeData      = RouteTable.Routes.GetRouteData(currentContext);
         routeData.Values["controller"] = controllerName;
         routeData.Values["action"]     = actionName;
         DomainRoute domainRoute = routeData.Route as DomainRoute;
         if (domainRoute != null)
         {
             DomainData domain = domainRoute.GetDomainData(new RequestContext(currentContext, routeData), routeData.Values);
             return(htmlHelper.ActionLink(linkText, actionName, controllerName, domain.Protocol, domain.Host, string.Empty, routeData.Values, null));
         }
     }
     return(htmlHelper.ActionLink(linkText, actionName, controllerName, routeValues, htmlAttributes));
 }