本文整理汇总了C#中System.Web.Mvc.UrlHelper.RouteUrl方法的典型用法代码示例。如果您正苦于以下问题:C# UrlHelper.RouteUrl方法的具体用法?C# UrlHelper.RouteUrl怎么用?C# UrlHelper.RouteUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.UrlHelper
的用法示例。
在下文中一共展示了UrlHelper.RouteUrl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HomeViewModel
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)
};
}
示例2: Generate
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;
}
示例3: GetAuthorizerScripts
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);
}
示例4: Generate
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;
}
示例5: OnActionExecuting
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" }));
}
}
}
示例6: Generate
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;
}
示例7: TransferActionResult
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);
};
}
示例8: CreateUri
/// <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);
}
示例9: Execute
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());
}
示例10: GetEnsuredUrl
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);
}
示例11: GetUrl
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;
}
示例12: Application_Error
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);
}
}
示例13: LocalizationUrl
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;
}
示例14: GetUrl
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;
}
示例15: Generate
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;
}