本文整理汇总了C#中RouteValueDictionary类的典型用法代码示例。如果您正苦于以下问题:C# RouteValueDictionary类的具体用法?C# RouteValueDictionary怎么用?C# RouteValueDictionary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RouteValueDictionary类属于命名空间,在下文中一共展示了RouteValueDictionary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPageRoute
public static RouteValueDictionary GetPageRoute(this RequestContext requestContext, ContentReference contentLink)
{
var values = new RouteValueDictionary();
values[RoutingConstants.NodeKey] = contentLink;
values[RoutingConstants.LanguageKey] = ContentLanguage.PreferredCulture.Name;
return values;
}
示例2: GetRouteDescriptorKey
public string GetRouteDescriptorKey(HttpContextBase httpContext, RouteBase routeBase) {
var route = routeBase as Route;
var dataTokens = new RouteValueDictionary();
if (route != null) {
dataTokens = route.DataTokens;
}
else {
var routeData = routeBase.GetRouteData(httpContext);
if (routeData != null) {
dataTokens = routeData.DataTokens;
}
}
var keyBuilder = new StringBuilder();
if (route != null) {
keyBuilder.AppendFormat("url={0};", route.Url);
}
// the data tokens are used in case the same url is used by several features, like *{path} (Rewrite Rules and Home Page Provider)
if (dataTokens != null) {
foreach (var key in dataTokens.Keys) {
keyBuilder.AppendFormat("{0}={1};", key, dataTokens[key]);
}
}
return keyBuilder.ToString().ToLowerInvariant();
}
示例3: RegisterRoutes
public void RegisterRoutes(RouteCollection routes)
{
//Register 1 route
var basePath = Config.GetBasePath();
var constrasints = new RouteValueDictionary {{"method", new ApiHttpMethodConstraint("OPTIONS")}};
routes.Add(new Route(basePath + "{*path}", null, constrasints, new ApiAccessRouteHandler()));
}
示例4: OnActionExecuting
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
base.OnActionExecuting(filterContext);
var principal = HttpContext.Current.User as IClaimsPrincipal;
var buffer = new StringBuilder();
if (principal != null && principal.Identity.IsAuthenticated)
{
foreach (var claim in Claims)
{
if (!principal.Identities[0].Claims.Any(c => c.ClaimType == claim))
{
buffer.AppendLine(String.Format("Claim '{0}' not provided.", claim));
}
}
if (buffer.Length > 0)
{
var redirectTargetDictionary = new RouteValueDictionary
{
{"action", "Error"},
{"controller", "Home"},
{"message", buffer.ToString()}
};
filterContext.Result = new RedirectToRouteResult(redirectTargetDictionary);
}
}
}
示例5: GetVirtualPath
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
VirtualPathData path = base.GetVirtualPath(requestContext, values);
if (path != null)
{
string virtualPath = path.VirtualPath;
var lastIndexOf = virtualPath.LastIndexOf("?");
if (lastIndexOf != 0)
{
if (lastIndexOf > 0)
{
string leftPart = virtualPath.Substring(0, lastIndexOf).ToLowerInvariant();
string queryPart = virtualPath.Substring(lastIndexOf);
path.VirtualPath = leftPart + queryPart;
}
else
{
path.VirtualPath = path.VirtualPath.ToLowerInvariant();
}
}
}
return path;
}
示例6: GetOutput
private static string GetOutput(object tokenReplacements)
{
// Read the contents of the html template.
var assembly = Assembly.GetExecutingAssembly();
var fileName = "{0}.LogRoutes.html".FormatWith(typeof(LogRoutesHandler).Namespace);
string fileContent;
using (var stream = assembly.GetManifestResourceStream(fileName))
{
if (stream == null)
throw new AttributeRoutingException(
"The file \"{0}\" cannot be found as an embedded resource.".FormatWith(fileName));
using (var reader = new StreamReader(stream))
fileContent = reader.ReadToEnd();
}
// Replace tokens in the template with appropriate content
var outputBuilder = new StringBuilder(fileContent);
var tokenReplacementsDictionary = new RouteValueDictionary(tokenReplacements);
foreach (var key in tokenReplacementsDictionary.Keys)
outputBuilder.Replace("{{{0}}}".FormatWith(key), tokenReplacementsDictionary[key].ToString());
return outputBuilder.ToString();
}
示例7: 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;
}
示例8: RegisterRoutes
public static void RegisterRoutes(RouteCollection routes)
{
var def = new RouteValueDictionary(new { user = "demo" });
var reg = new RouteValueDictionary(new { user = "\\w+" });
// Register a route for Page/{User}
routes.MapPageRoute(
"user-page", // Route name
"w/{user}", // Route URL
"~/Pv.aspx", // Web page to handle route
true,
def,
reg
);
// Register a route for Page/{User}
routes.MapPageRoute(
"user-card", // Route name
"c/{user}", // Route URL
"~/Cv.aspx", // Web page to handle route
true,
def,
reg
);
// Register a route for Page/{User}
routes.MapPageRoute(
"user-imgs", // Route name
"p/{user}", // Route URL
"~/Id.aspx", // Web page to handle route
true,
def,
reg
);
}
示例9: Match
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) {
object value;
if (values.TryGetValue(parameterName, out value)) {
var parameterValue = Convert.ToString(value);
var path = FindPath(parameterValue);
if (path == null) {
return false;
}
var archiveData = FindArchiveData(parameterValue);
if (archiveData == null) {
return false;
}
try {
// is this a valid date ?
archiveData.ToDateTime();
}
catch {
return false;
}
var autoroute = _pathResolutionService.GetPath(path);
return autoroute != null && autoroute.Is<BlogPart>();
}
return false;
}
示例10: GetConfigurationRoute
/// <summary>
/// Gets a route for provider configuration
/// </summary>
/// <param name="actionName">Action name</param>
/// <param name="controllerName">Controller name</param>
/// <param name="routeValues">Route values</param>
public void GetConfigurationRoute(out string actionName, out string controllerName, out RouteValueDictionary routeValues)
{
// no configuration required
actionName = null;
controllerName = null;
routeValues = null;
}
开发者ID:tomvanenckevort,项目名称:NopCommerce.MultipleParentCategories,代码行数:13,代码来源:MultipleParentsPlugin.cs
示例11: Match
/// <summary>
///
/// </summary>
/// <param name="httpContext"></param>
/// <param name="route"></param>
/// <param name="parameterName"></param>
/// <param name="values"></param>
/// <param name="routeDirection"></param>
/// <returns></returns>
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
if (values[parameterName].ToString().ToLower() == "rqitems")
return true;
else
return false;
}
示例12: AddNodeRecursive
private SiteMapNode AddNodeRecursive(XmlNode xmlNode, SiteMapNode parent, RequestContext context)
{
var routeValues = (from XmlNode attrib in xmlNode.Attributes
where !reservedNames.Contains(attrib.Name.ToLower())
select new { attrib.Name, attrib.Value }).ToDictionary(x => x.Name, x => (object)x.Value);
RouteValueDictionary routeDict = new RouteValueDictionary(routeValues);
VirtualPathData virtualPathData = RouteTable.Routes.GetVirtualPath(context, routeDict);
if (virtualPathData == null)
{
string message = "RoutingSiteMapProvider is unable to locate Route for " +
"Controller: '" + routeDict["controller"] + "', Action: '" + routeDict["action"] + "'. " +
"Make sure a route has been defined for this SiteMap Node.";
throw new InvalidOperationException(message);
}
string url = virtualPathData.VirtualPath;
string title = xmlNode.Attributes["title"].Value;
SiteMapNode node = new SiteMapNode(this, Guid.NewGuid().ToString(), url, title);
base.AddNode(node, parent);
foreach (XmlNode childNode in xmlNode.ChildNodes)
{
AddNodeRecursive(childNode, node, context);
}
return node;
}
示例13: MapAreaRoute
// TODO: Remove when https://github.com/aspnet/Mvc/issues/4846 is fixed
public static IRouteBuilder MapAreaRoute(this IRouteBuilder routeBuilder,
string name,
string area,
string template,
string controller,
string action)
{
if (routeBuilder == null)
{
throw new ArgumentNullException(nameof(routeBuilder));
}
if (string.IsNullOrEmpty(area))
{
throw new ArgumentException(nameof(area));
}
var defaultsDictionary = new RouteValueDictionary();
defaultsDictionary["area"] = area;
defaultsDictionary["controller"] = controller;
defaultsDictionary["action"] = action;
var constraintsDictionary = new RouteValueDictionary();
constraintsDictionary["area"] = new StringRouteConstraint(area);
routeBuilder.MapRoute(name, template, defaultsDictionary, constraintsDictionary, null);
return routeBuilder;
}
示例14: Match
// To only allow *supported* cultures as the first part of the route, instead of anything in the format xx or xx-xx comment the lower method
// and uncomment this one, and make CultureManager.CultureIsSupported public.
//public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
//{
// if (!values.ContainsKey(parameterName))
// return false;
// string potentialCultureName = (string)values[parameterName];
// return CultureManager.CultureIsSupported(potentialCultureName);
//}
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
if (!values.ContainsKey(parameterName))
return false;
string potentialCultureName = (string)values[parameterName];
return CultureFormatChecker.FormattedAsCulture(potentialCultureName);
}
示例15: BuildLink
public ActionLink BuildLink(Theme theme)
{
RouteValueDictionary routeValueDictionary = new RouteValueDictionary();
routeValueDictionary.Add("id", theme.Id);
ActionLink actionLink = new ActionLink("Play", "Training", routeValueDictionary);
return actionLink;
}