public static MvcHtmlString GetAuthorizerScripts(this HtmlHelper helper, BaseType libraryBase, CommonResources includedResources) { UrlHelper Urls = new UrlHelper(helper.ViewContext.RequestContext); List<TagBuilder> LibrarySupportingElements = new List<TagBuilder>(); TagBuilder OpenIdLibrary = new TagBuilder("script"); OpenIdLibrary.Attributes.Add(new KeyValuePair<string,string>( "type", "text/javascript")); switch(libraryBase) { case BaseType.Jquery: OpenIdLibrary.Attributes.Add(new KeyValuePair<string, string>("src", Urls.RouteUrl("AuthorizationResources", new {resourceType = "Scripts", resourceName = "openid-jquery.js"}))); TagBuilder LanguageFile = new TagBuilder("script"); LanguageFile.Attributes.Add(new KeyValuePair<string, string>("type", "text/javascript")); LanguageFile.Attributes.Add(new KeyValuePair<string, string>("src", Urls.RouteUrl("AuthorizationResources", new { resourceType = "Scripts", resourceName = "openid-en.js" }))); LibrarySupportingElements.Add(LanguageFile); break; default: throw new InvalidOperationException(); } string RawResult = OpenIdLibrary.ToString(TagRenderMode.Normal); LibrarySupportingElements.ForEach(Lib => RawResult += Lib.ToString(TagRenderMode.Normal)); return MvcHtmlString.Create(RawResult); }
public Uri Generate(RequestContext requestContext, INavigatable navigatable, RouteValueDictionary routeValues) { if (requestContext == null) { throw new ArgumentNullException(nameof(requestContext)); } if (navigatable == null) { throw new ArgumentNullException(nameof(navigatable)); } var urlHelper = new UrlHelper(requestContext); if (!String.IsNullOrEmpty(navigatable.RouteName)) { return new Uri(uriString: urlHelper.RouteUrl(navigatable.RouteName, routeValues)); } if (!String.IsNullOrEmpty(navigatable.ControllerName) && !String.IsNullOrEmpty(navigatable.ActionName)) { return new Uri(uriString: urlHelper.Action(navigatable.ActionName, navigatable.ControllerName, routeValues), uriKind: UriKind.Relative); } if (routeValues.Any()) { return new Uri(uriString: urlHelper.RouteUrl(routeValues)); } return null; }
public HomeViewModel(UrlHelper urlHelper,CatalogStatistic catalogStatistic ) { TrainingProvidersStatistic = new StatisticViewModel { Title = "Providers", Count = catalogStatistic.TrainingProviderCount, Url = urlHelper.RouteUrl(AppConstants.RouteNames.AllTrainingProviders) }; CategoriesStatistic = new StatisticViewModel { Title = "Categories", Count = catalogStatistic.CategoryCount, Url = urlHelper.RouteUrl(AppConstants.RouteNames.AllCategories) }; CoursesStatistic = new StatisticViewModel { Title = "Courses", Count = catalogStatistic.CourseCount, Url = urlHelper.RouteUrl(AppConstants.RouteNames.AllCourses) }; AuthorsStatistic = new StatisticViewModel { Title = "Authors", Count = catalogStatistic.AuthorCount, Url = urlHelper.RouteUrl(AppConstants.RouteNames.AllAuthors) }; }
public string Generate(RequestContext requestContext, INavigatable navigationItem, RouteValueDictionary routeValues) { Guard.IsNotNull(requestContext, "requestContext"); Guard.IsNotNull(navigationItem, "navigationItem"); UrlHelper urlHelper = new UrlHelper(requestContext); string generatedUrl = null; if (!string.IsNullOrEmpty(navigationItem.RouteName)) { generatedUrl = urlHelper.RouteUrl(navigationItem.RouteName, routeValues); } else if (!string.IsNullOrEmpty(navigationItem.ControllerName) && !string.IsNullOrEmpty(navigationItem.ActionName)) { generatedUrl = urlHelper.Action(navigationItem.ActionName, navigationItem.ControllerName, routeValues, null, null); } else if (!string.IsNullOrEmpty(navigationItem.Url)) { generatedUrl = navigationItem.Url.StartsWith("~/", StringComparison.Ordinal) ? urlHelper.Content(navigationItem.Url) : navigationItem.Url; } else if (routeValues.Any()) { generatedUrl = urlHelper.RouteUrl(routeValues); } return generatedUrl; }
public override void OnActionExecuting(ActionExecutingContext filterContext) { var context = filterContext.RequestContext; var controller = context.RouteData.Values["controller"]; var urlHelper = new UrlHelper(filterContext.RequestContext); if (!filterContext.HttpContext.User.Identity.IsAuthenticated || SessionManager.UserInfo == null) { filterContext.HttpContext.Response.Redirect(urlHelper.RouteUrl(new { controller = "Secure", action = "Index" })); } else { bool hasRight = false; if (SessionManager.UserInfo.IsSystemAdministrator) return ; if (Right == Permissions.SA && !SessionManager.UserInfo.IsSystemAdministrator) { } else { foreach (var item in SessionManager.UserInfo.Permissions) { if (item.Actions.Contains(controller) && (item.Permissions.Contains(this.Right) || item.Permissions.Contains(Permissions.Full))) { hasRight = true; } } } if (!hasRight) { filterContext.HttpContext.Response.Redirect(urlHelper.RouteUrl(new { controller = "Secure", action = "AccessDenied" })); } } }
public static string Generate(RequestContext requestContext, NavigationRequest navigationItem, RouteValueDictionary routeValues) { if (requestContext == null) throw new ArgumentNullException("requestContext"); if (navigationItem == null) throw new ArgumentNullException("navigationItem"); var urlHelper = new UrlHelper(requestContext); string generatedUrl = null; if (!string.IsNullOrEmpty(navigationItem.RouteName)) { generatedUrl = urlHelper.RouteUrl(navigationItem.RouteName, routeValues); } else if (!string.IsNullOrEmpty(navigationItem.ControllerName) && !string.IsNullOrEmpty(navigationItem.ActionName)) { generatedUrl = urlHelper.Action(navigationItem.ActionName, navigationItem.ControllerName, routeValues, null, null); } else if (!string.IsNullOrEmpty(navigationItem.Url)) { generatedUrl = navigationItem.Url.StartsWith("~/", StringComparison.Ordinal) ? urlHelper.Content(navigationItem.Url) : navigationItem.Url; } else if (routeValues.Any()) { generatedUrl = urlHelper.RouteUrl(routeValues); } return generatedUrl; }
/// <summary> /// Creates the uri which should be visited when the item is clicked /// </summary> /// <param name="helper"> Uri helper (to be able to generate absolute uris) </param> /// <returns> Created URI </returns> /// <remarks> /// Add the route item "area" for area routes /// </remarks> public Uri CreateUri(UrlHelper helper) { var routeName = (string)_route["area"]; if (routeName != null) { return new Uri(helper.RouteUrl(routeName, _route), UriKind.Relative); } return new Uri(helper.RouteUrl(_route), UriKind.Relative); }
public TransferActionResult(string routeName, RouteValueDictionary routeValues, bool preserveForm = true) : this(preserveForm) { this.UrlBuilder = delegate(ControllerContext context) { var helper = new UrlHelper(context.RequestContext, System.Web.Routing.RouteTable.Routes); return string.IsNullOrEmpty(routeName) ? helper.RouteUrl(routeValues) : helper.RouteUrl(routeName, routeValues); }; }
public void Execute() { // Initialize engine EngineContext.Initialize(false); // Resolve any services var coreSettings = EngineContext.Current.Resolve<CoreSettings>(); var httpContext = EngineContext.Current.Resolve<HttpContextBase>(); var locationService = EngineContext.Current.Resolve<ILocationService>(); var pageService = EngineContext.Current.Resolve<IPageService>(); var projectService = EngineContext.Current.Resolve<IProjectService>(); var successStoryService = EngineContext.Current.Resolve<ISuccessStoryService>(); var sb = new StringBuilder(); var nodes = new List<XmlNode>(); var urlHelper = new UrlHelper(httpContext.Request.RequestContext); nodes.Add(new XmlNode(urlHelper.RouteUrl("HomePage"), 1)); nodes.Add(new XmlNode(urlHelper.RouteUrl("Contact"), 0.1m)); nodes.Add(new XmlNode(urlHelper.RouteUrl("SiteMap"), 0.1m)); nodes.Add(new XmlNode(urlHelper.RouteUrl("AuthenticationLogin"), 0.0m)); nodes.Add(new XmlNode(urlHelper.RouteUrl("SuccessStoryListing"), 0.7m)); nodes.Add(new XmlNode(urlHelper.RouteUrl("ProjectListing"), 0.8m)); nodes.Add(new XmlNode(urlHelper.RouteUrl("AddProject"), 0.0m)); // Success stories nodes.AddRange(successStoryService.GetAllSuccessStories().Select(x => new XmlNode(urlHelper.RouteUrl("SuccessStory", new { seoName = SeoExtensions.GetSeoName(x.Title) }), 0.6m))); // Pages nodes.AddRange(pageService.GetAllPages(1, -1).Select(x => new XmlNode(urlHelper.Action("Detail", "Static", new { x.Id }), Math.Round(x.Priority, 1)))); // Locations nodes.AddRange(locationService.GetAllCachedLocations().Select(x => new XmlNode(urlHelper.RouteUrl("ProjectListingLocation", new { locationSeoName = x.SeoName }), 0.9m))); // Projects foreach (var project in projectService.GetAllCachedProjects()) { var primaryLocation = project.Locations.First(l => l.Primary).Location; nodes.Add(new XmlNode(urlHelper.RouteUrl("ProjectDetail", new { locationSeoName = primaryLocation.SeoName, seoName = project.GetSeoName(), id = project.Id }), 0.8m)); } sb.AppendLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); sb.AppendLine("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">"); foreach (var node in nodes.OrderByDescending(x => x.Priority)) { sb.AppendLine("<url>"); sb.AppendLine("<loc>" + coreSettings.Domain.TrimEnd('/') + node.Url + "</loc>"); sb.AppendLine("<lastmod>" + DateTime.Now.ToString("yyyy-MM-dd") + "</lastmod>"); sb.AppendLine("<changefreq>monthly</changefreq>"); sb.AppendLine("<priority>" + node.Priority + "</priority>"); sb.AppendLine("</url>"); } sb.AppendLine("</urlset>"); string filePath = HostingEnvironment.MapPath("~/site-map.xml"); File.WriteAllText(filePath, sb.ToString()); }
protected override string GetUrl(ControllerContext context) { var urlHelper = new UrlHelper(context.RequestContext); string actionUrl = string.Empty; if (this.routeValues == null) actionUrl = urlHelper.RouteUrl(this.routeName, this.routeValuesDict); else if (this.routeValues != null) actionUrl = urlHelper.RouteUrl(this.routeName, this.routeValues); else actionUrl = urlHelper.RouteUrl(this.routeName); string url = String.Format("{0}://{1}{2}", context.HttpContext.Request.Url.Scheme, context.HttpContext.Request.Url.Authority, actionUrl); return url; }
private static string GetEnsuredUrl(string routeName, RequestContext requestContext) { var routeValues = requestContext.RouteData.Values ?? new RouteValueDictionary(); var slugValue = (routeValues[SlugKeyName] as string) ?? string.Empty; var ensuredSlugValue = ArticleSlugUtility.DecodeSlug(slugValue); ensuredSlugValue = ArticleSlugUtility.EncodeSlug(ensuredSlugValue); routeValues[SlugKeyName] = ensuredSlugValue; var urlHelper = new UrlHelper(requestContext); return (!string.IsNullOrWhiteSpace(routeName)) ? urlHelper.RouteUrl(routeName, routeValues) : urlHelper.RouteUrl(routeValues); }
protected void Application_Error() { var exception = Server.GetLastError(); var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext); if (exception is UrlNotFoundException) { Response.Redirect(urlHelper.RouteUrl("Error404"), true); } else if (exception is SqlException) { Response.Redirect(urlHelper.RouteUrl("Error500"), true); } }
private static string GetRouteUrl(RequestContext context, RouteValueDictionary routes) { var urlHelper = new UrlHelper(context); var url = urlHelper.RouteUrl(routes); return url; }
/// <summary> /// Loads the menu items. /// </summary> /// <param name="urlHelper">The URL helper.</param> /// <param name="runAsTenant">The run as tenant id.</param> /// <returns></returns> public static IList<MenuItem> LoadMenuItems(UrlHelper urlHelper) { var repo = ServiceLocator.Current.GetInstance<IRepositoryFactory>(); var repoMenu = repo.CreateWithGuid<Menu>(); var menus = repoMenu.GetAll().ToList(); var items = new List<MenuItem>(); foreach (var menu in menus) { var link = string.Empty; link = urlHelper.RouteUrl("Default", new { controller = menu.Controller, action = menu.Action }); var item = new MenuItem() { Text = menu.Name, Link = link, IsAdministration = menu.IsAdministration }; items.Add(item); } //var items = new List<MenuItem>(); if (items == null) items = new List<MenuItem>(); return items; }
/// <summary> /// Called by the ASP.NET MVC framework after the action method executes. /// </summary> /// <param name="filterContext">The filter context.</param> public override void OnActionExecuted(ActionExecutedContext filterContext) { if (filterContext == null || !filterContext.HttpContext.Request.IsAjaxRequest()) { return; } // Preparing Json object for AJAX.success processing in forms.js javascript string destinationUrl = string.Empty; if (filterContext.Result is RedirectResult) { var result = filterContext.Result as RedirectResult; destinationUrl = UrlHelper.GenerateContentUrl(result.Url, filterContext.HttpContext); } if (filterContext.Result is RedirectToRouteResult) { var result = filterContext.Result as RedirectToRouteResult; var helper = new UrlHelper(filterContext.RequestContext); destinationUrl = helper.RouteUrl(result.RouteValues); } // Rendered context is getting reloaded by AJAX.success in forms.js javascript if (filterContext.Result is ViewResult) { return; } var jsonResult = new JsonResult { Data = new { resultType = "Redirect", redirectUrl = destinationUrl } }; filterContext.Result = jsonResult; }
public override void OnActionExecuting(ActionExecutingContext filterContext) { if (SessionManager.UserInfo == null) { var urlHelper = new UrlHelper(filterContext.RequestContext); if (RedirectToClientLogin) { filterContext.HttpContext.Response.Redirect(urlHelper.RouteUrl(new { controller = "Home", action = "ClientLogin", Area = "" })); } else { filterContext.HttpContext.Response.Redirect(urlHelper.RouteUrl(new { controller = "Secure", action = "Index" })); } } }
private string BuildUrl(ControllerContext filterContext) { UrlHelper urlHelper = new UrlHelper(filterContext.RequestContext); string url; if (!string.IsNullOrEmpty(RouteName)) { url = urlHelper.RouteUrl(RouteName); } else if (!string.IsNullOrEmpty(ControllerName) && !string.IsNullOrEmpty(ActionName)) { url = urlHelper.Action(ActionName, ControllerName); } else if (!string.IsNullOrEmpty(ActionName)) { url = urlHelper.Action(ActionName); } else { url = filterContext.HttpContext.Request.RawUrl; } url += "?" + filterContext.HttpContext.Request.QueryString; url = url.TrimEnd('?'); return url; }
public static string GetUrl(RequestContext requestContext, RouteValueDictionary routeValueDictionary) { RouteValueDictionary urlData = new RouteValueDictionary(); UrlHelper urlHelper = new UrlHelper(requestContext); int i = 0; foreach (var item in routeValueDictionary) { if (string.Empty == item.Value as string) { i++; urlData.Add(item.Key, string.Format(ReplaceFormatString, i)); } else { urlData.Add(item.Key, item.Value); } } var url = urlHelper.RouteUrl(urlData); for (int index = 1; index <= i; index++) { url = url.Replace(string.Format(ReplaceFormatString, index), string.Empty); } return url; }
/// <summary> /// Renders an <li> tag containing a "Menu Item Link" which is a standard link that displays a marker indicating if its target is the current action. /// </summary> /// <param name="icon">The CSS class for an icon to use for the menu item</param> /// <param name="name">The text to display for the link</param> public static HtmlString MenuLink(this HtmlHelper self, string name, string icon, string action, string controller, object routeValues) { if (self == null) { throw new ArgumentNullException("self"); } var url = new UrlHelper(self.ViewContext.RequestContext); RouteValueDictionary target; if (routeValues != null) { target = new RouteValueDictionary(routeValues); } else { target = new RouteValueDictionary(); } target["action"] = action; target["controller"] = controller; var li = new TagBuilder("li"); var a = new TagBuilder("a"); var i = new TagBuilder("i"); if (SameRoute(target, self.ViewContext.RouteData.Values)) { li.AddCssClass("active"); } i.AddCssClass(icon); a.Attributes["href"] = url.RouteUrl(target); a.InnerHtml = i.ToString(TagRenderMode.Normal) + " " + name; li.InnerHtml = a.ToString(TagRenderMode.Normal); return new HtmlString(li.ToString(TagRenderMode.Normal)); }
public static IList<MenuItem> GetTopMenu(UrlHelper url) { var items = new List<MenuItem> { new MenuItem {Title = "Back To Blog", Url = url.RouteUrl("homepage"), Type = MenuButtonType.Plain}, new MenuItem {Title = "Posts", Url = url.Action("Index", "Posts"), Type = MenuButtonType.Plain}, new MenuItem {Title = "Add new post", Url = url.Action("Add", "Posts"), Type = MenuButtonType.Add}, new MenuItem {Title = "Sections", Url = url.Action("Index", "Sections"), Type = MenuButtonType.Plain}, new MenuItem {Title = "Add new section", Url = url.Action("Add", "Sections"), Type = MenuButtonType.Add}, new MenuItem {Title = "Users", Url = url.Action("Index", "Users"), Type = MenuButtonType.Plain}, new MenuItem {Title = "Add new user", Url = url.Action("Add", "Users"), Type = MenuButtonType.Add}, new MenuItem {Title = "Tools", Type = MenuButtonType.Toggle, SubMenus = new List<MenuItem> { new MenuItem {Title = "Settings", Url = url.Action("Index", "Settings"), Type = MenuButtonType.Plain}, new MenuItem {Title = "RSS Future Access", Url = url.Action("RssFutureAccess", "Settings"), Type = MenuButtonType.Plain}, new MenuItem {Title = "Reddit submission", Url = url.Action("RedditSubmission", "Settings"), Type = MenuButtonType.Plain}, } }, }; AnalyzeMenuItems(items, url.RequestContext.HttpContext.Request.Url ?? new Uri("/")); return items; }
private static string Generate(RequestContext requestContext, SiteMapNode navigationItem, RouteValueDictionary routeValues) { Check.Argument.IsNotNull(requestContext, "requestContext"); Check.Argument.IsNotNull(navigationItem, "navigationItem"); var urlHelper = new UrlHelper(requestContext); string generatedUrl = null; if (!string.IsNullOrEmpty(navigationItem.RouteName)) { generatedUrl = urlHelper.RouteUrl(navigationItem.RouteName, routeValues); } else if (!string.IsNullOrEmpty(navigationItem.ControllerName) && !string.IsNullOrEmpty(navigationItem.ActionName)) { generatedUrl = urlHelper.Action(navigationItem.ActionName, navigationItem.ControllerName, routeValues, null, null); } else if (!string.IsNullOrEmpty(navigationItem.Url)) { generatedUrl = navigationItem.Url.StartsWith("~/", StringComparison.Ordinal) ? urlHelper.Content(navigationItem.Url) : navigationItem.Url; //var rgx = new Regex(@"#.*$"); //if(rgx.IsMatch(generatedUrl)) //{ // generatedUrl = rgx.Match(generatedUrl).Value; //} } else if (routeValues.Any()) { generatedUrl = urlHelper.RouteUrl(routeValues); } return generatedUrl; }
/// <summary> /// Initializes a new instance of the FeedActionResult class /// </summary> /// <param name="blogName">Name of the blog</param> /// <param name="description">Feed description</param> /// <param name="format">Format of the feed</param> /// <param name="url">A URL Helper</param> /// <param name="posts">The posts to include in the feed</param> public FeedActionResult(string blogName, string description, FeedFormat format, UrlHelper url, IEnumerable<BlogPost> posts) { Guid blogPostId; string postRelative; SyndicationItem item; List<SyndicationItem> items = new List<SyndicationItem>(); // Specify the type of feed Format = format; // Initialize the current feed Feed = new SyndicationFeed(blogName, description, new Uri(url.RouteUrl("Default"), UriKind.Relative)); //load the posts as items foreach (BlogPost post in posts) { blogPostId = post.BlogPostId; postRelative = url.Action( "Details", "Posts", new { year = post.PostedDate.Value.Year, month = post.PostedDate.Value.Month, day = post.PostedDate.Value.Day, id = blogPostId }); item = new SyndicationItem(post.Title, post.Post, new Uri(postRelative, UriKind.Relative), post.BlogPostId.ToString(), post.PostedDate.Value); items.Add(item); } Feed.Items = items.OrderByDescending(x => x.LastUpdatedTime); }
public static string LocalizationUrl(this HtmlHelper helper, string cultureName) { var routeValues = new RouteValueDictionary(helper.ViewContext.RouteData.Values); var queryString = helper.ViewContext.HttpContext.Request.QueryString; foreach (string key in queryString) { if (queryString[key] != null && !string.IsNullOrWhiteSpace(key)) { if (routeValues.ContainsKey(key)) { routeValues[key] = queryString[key]; } else { routeValues.Add(key, queryString[key]); } } } routeValues[Constants.LanguageRouteName] = cultureName; var urlHelper = new UrlHelper(helper.ViewContext.RequestContext); string url = urlHelper.RouteUrl(routeValues); return url; }
/// <summary> /// Method that is overridden, that handles creation of child urls. /// Use the method WriteUrlLocation() within this method. /// </summary> /// <param name="urlHelper">URL helper</param> protected override void GenerateUrlNodes(UrlHelper urlHelper) { //home page var homePageUrl = urlHelper.RouteUrl("HomePage", null, "http"); WriteUrlLocation(homePageUrl, UpdateFrequency.Weekly, DateTime.UtcNow); //search products var productSearchUrl = urlHelper.RouteUrl("ProductSearch", null, "http"); WriteUrlLocation(productSearchUrl, UpdateFrequency.Weekly, DateTime.UtcNow); //contact us var contactUsUrl = urlHelper.RouteUrl("ContactUs", null, "http"); WriteUrlLocation(contactUsUrl, UpdateFrequency.Weekly, DateTime.UtcNow); //news if (_newsSettings.Enabled) { var url = urlHelper.RouteUrl("NewsArchive", null, "http"); WriteUrlLocation(url, UpdateFrequency.Weekly, DateTime.UtcNow); } //blog if (_blogSettings.Enabled) { var url = urlHelper.RouteUrl("Blog", null, "http"); WriteUrlLocation(url, UpdateFrequency.Weekly, DateTime.UtcNow); } //blog if (_forumSettings.ForumsEnabled) { var url = urlHelper.RouteUrl("Boards", null, "http"); WriteUrlLocation(url, UpdateFrequency.Weekly, DateTime.UtcNow); } //categories if (_commonSettings.SitemapIncludeCategories) { WriteCategories(urlHelper, 0); } //manufacturers if (_commonSettings.SitemapIncludeManufacturers) { WriteManufacturers(urlHelper); } //products if (_commonSettings.SitemapIncludeProducts) { WriteProducts(urlHelper); } //topics WriteTopics(urlHelper); }
private string GetUrl(string routeName) { new RouteConfigurator().RegisterRoutes(() => { }); var builder = new TestControllerBuilder(); var context = new RequestContext(builder.HttpContext, new RouteData()); context.HttpContext.Response.Expect(x => x.ApplyAppPathModifier(null)).IgnoreArguments().Do(new Func<string, string>(s => s)).Repeat.Any(); var urlhelper = new UrlHelper(context); return urlhelper.RouteUrl(routeName, new { sessionKey = "this-is-the-session", conferenceKey = "austincodecamp" }); }
public virtual string BuildNotificationUrl(RequestContext context) { var configuration = Configuration.Current; var urlHelper = new UrlHelper(context); var routeValues = new RouteValueDictionary(new {controller = configuration.NotificationController, action = configuration.NotificationAction}); string url = urlHelper.RouteUrl(null, routeValues, configuration.Protocol, configuration.NotificationHostName); return url; }
public static string NavImageLink(this HtmlHelper helper, string linkText, string imageTag, ActionResult action) { var urlHelper = new UrlHelper(helper.ViewContext.RequestContext, helper.RouteCollection); var tagBuilder = new TagBuilder("a"); tagBuilder.MergeAttribute("href", urlHelper.RouteUrl(action.GetRouteValueDictionary())); tagBuilder.InnerHtml = helper.ImgFor(imageTag) + linkText; return tagBuilder.ToString(TagRenderMode.Normal); }
public virtual string BuildSuccessfulTransactionUrl(RequestContext context, string vendorTxCode) { var configuration = Configuration.Current; var urlHelper = new UrlHelper(context); var routeValues = new RouteValueDictionary(new {controller = configuration.SuccessController, action = configuration.SuccessAction, vendorTxCode}); string url = urlHelper.RouteUrl(null, routeValues, configuration.Protocol, configuration.NotificationHostName); return url; }
/// <summary> /// Builds main menu /// </summary> public static MvcHtmlString BuildMainMenuItems(this HtmlHelper helper, UrlHelper urlHelper, string activeItemTitle) { var sb = new StringBuilder(); var menuItems = new[]{ new MenuItem("Главная", urlHelper.RouteUrl("Main")), new MenuItem("Программы",urlHelper.RouteUrl("AllTravels")), new MenuItem("Расписание", urlHelper.RouteUrl("EventSchedule")), new MenuItem("Статьи", urlHelper.RouteUrl("AllArticles")), new MenuItem("Фотогалерея", urlHelper.RouteUrl("AllAlbums")), new MenuItem("Книги", urlHelper.RouteUrl("AllBooks")), new MenuItem("Новости", urlHelper.RouteUrl("AllNews")), new MenuItem("Отзывы", "javascript:notImplemented()"), new MenuItem("Цены", "javascript:notImplemented()"), new MenuItem("Контакты", "javascript:notImplemented()") }; foreach (var menuItem in menuItems) { sb.AppendLine( string.Format("<li {0}><a href='{1}'>{2}</a></li>", (menuItem.Title == activeItemTitle) ? "class='active'" : string.Empty, menuItem.Url, menuItem.Title)); } return new MvcHtmlString(sb.ToString()); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { var urlHelper = new UrlHelper(filterContext.RequestContext); string url = HttpContext.Current.Request.RawUrl; if (SessionManager.AccessInfo == null) { filterContext.HttpContext.Response.Redirect(urlHelper.RouteUrl(new { controller = "Content", action = "SMS", area = "Content", Source = url })); } }
/// <summary> /// Gets the relative URL for the specified controller action. /// </summary> /// <param name="action">The controller action /// The action. /// </param> /// <typeparam name="TController">The generic parameter for the Controller class. /// </typeparam> /// <returns> /// The relative URL in the form '/Home/About'>. /// </returns> public string GetRelativeUrlFor <TController>(Expression <Action <TController> > action) where TController : Controller { var requestContext = new RequestContext(FakeHttpContext.Root(), new RouteData()); var actionRouteValues = Microsoft.Web.Mvc.Internal.ExpressionHelper.GetRouteValuesFromExpression(action); var urlHelper = new System.Web.Mvc.UrlHelper(requestContext, _routeCollection); var relativeUrl = urlHelper.RouteUrl(new RouteValueDictionary(actionRouteValues)); return(relativeUrl); }
/// <summary> /// If specific route can be found, return that route with the parameter tokens in route string. /// </summary> public static string JavaScriptReplaceableUrl(this UrlHelper urlHelper, ActionResult result) { var rvd = result.GetRouteValueDictionary(); string area = string.Empty; object token; if (rvd.TryGetValue("area", out token)) { area = token.ToString(); } if (!rvd.TryGetValue("controller", out token)) { throw new Exception("T4MVC JavascriptReplacableUrl could not locate controller in source dictionary"); } string controller = token.ToString(); if (!rvd.TryGetValue("SecureAction", out token)) { throw new Exception("T4MVC JavascriptReplacableUrl could not locate SecureAction in source dictionary"); } string SecureAction = token.ToString(); // This matches the ActionResult to a specific route (so we can get the exact URL) string specificSecureActionUrl = RouteTable.Routes.OfType <Route>() .Where(r => r.DataTokens.CompareValue("area", area) && r.Defaults.CompareValue("controller", controller) && r.Defaults.CompareValue("SecureAction", SecureAction)) .Select(r => r.Url) .FirstOrDefault(); if (String.IsNullOrEmpty(specificSecureActionUrl)) { return(urlHelper.RouteUrl(null, result.GetRouteValueDictionary())); } return(urlHelper.Content("~/" + specificSecureActionUrl)); }
public static string RouteUrl(this UrlHelper urlHelper, string routeName, ActionResult result, string protocol, string hostName) { return(urlHelper.RouteUrl(routeName, result.GetRouteValueDictionary(), protocol ?? result.GetT4MVCResult().Protocol, hostName)); }
public static string SecureAction(this UrlHelper urlHelper, ActionResult result, string protocol = null, string hostName = null) { return(urlHelper.RouteUrl(null, result.GetRouteValueDictionary(), protocol ?? result.GetT4MVCResult().Protocol, hostName)); }
private static string SecureActionAbsolute(this UrlHelper urlHelper, ActionResult result) { return ($"{urlHelper.RequestContext.HttpContext.Request.Url.GetLeftPart(UriPartial.Authority)}{urlHelper.RouteUrl(T4Extensions.GetRouteValueDictionary(result))}"); }
public static string RouteUrl(this UrlHelper urlHelper, ActionResult result) { return(urlHelper.RouteUrl(null, result, null, null)); }
public static string RouteUrl(this UrlHelper urlHelper, string routeName, ActionResult result, string protocol) { return(urlHelper.RouteUrl(routeName, result, protocol, null)); }
public static string RouteCultureUrl(this System.Web.Mvc.UrlHelper UrlHelper, RouteValueDictionary RouteValueDictionary, string Lang) { return(UrlHelper.RouteUrl(new { controller = RouteValueDictionary["controller"], action = RouteValueDictionary["action"], culture = Lang })); }
public static string Action(this UrlHelper urlHelper, ActionResult result) { return(urlHelper.RouteUrl(null, result.GetRouteValueDictionary())); }
public static string RouteUrl(this UrlHelper urlHelper, string routeName, Task <ActionResult> taskResult, string protocol, string hostName) { return(urlHelper.RouteUrl(routeName, taskResult.Result, protocol, hostName)); }
public static string AbsoluteRouteUrl(this System.Web.Mvc.UrlHelper urlHelper, string routeName, object routeValues = null) { string scheme = urlHelper.RequestContext.HttpContext.Request.Url.Scheme; return(urlHelper.RouteUrl(routeName, routeValues, scheme)); }
public static string RouteUrl(this UrlHelper urlHelper, string routeName, Task <ActionResult> taskResult) { return(urlHelper.RouteUrl(routeName, taskResult.Result, null, null)); }
public static string ActionAbsolute(this UrlHelper urlHelper, ActionResult result) { return(string.Format("{0}{1}", urlHelper.RequestContext.HttpContext.Request.Url.GetLeftPart(UriPartial.Authority), urlHelper.RouteUrl(result.GetRouteValueDictionary()))); }