本文整理汇总了C#中RouteValueDictionary.Where方法的典型用法代码示例。如果您正苦于以下问题:C# RouteValueDictionary.Where方法的具体用法?C# RouteValueDictionary.Where怎么用?C# RouteValueDictionary.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RouteValueDictionary
的用法示例。
在下文中一共展示了RouteValueDictionary.Where方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ActionButton
/// <summary>
///
/// </summary>
/// <param name="htmlHelper"></param>
/// <param name="linkText"></param>
/// <param name="icon"></param>
/// <param name="actionName"></param>
/// <param name="controllerName"></param>
/// <param name="routeValues"></param>
/// <param name="htmlAttributes"></param>
/// <param name="iconHtmlAttributes"></param>
/// <returns></returns>
public static MvcHtmlString ActionButton(this HtmlHelper htmlHelper, string linkText, string icon, string actionName, string controllerName, object routeValues, object htmlAttributes, object iconHtmlAttributes)
{
RouteValueDictionary tmpAttributes = new RouteValueDictionary(htmlAttributes);
RouteValueDictionary attributes = new RouteValueDictionary(tmpAttributes.Where(a => !a.Key.StartsWith("data_"))
.Select(p => new { p.Key, p.Value })
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value));
foreach (var item in tmpAttributes.Where(a => a.Key.StartsWith("data_")))
{
attributes.Add(item.Key.Replace("data_", "data-"), item.Value);
}
TagBuilder linkTag = new TagBuilder("a");
RouteValueDictionary iconAttributes = new RouteValueDictionary(iconHtmlAttributes);
TagBuilder iTag = new TagBuilder("i");
iTag.AddCssClass(icon);
iTag.MergeAttributes(iconAttributes);
linkTag.AddCssClass("btn");
linkTag.MergeAttributes(attributes);
UrlHelper url = new UrlHelper(htmlHelper.ViewContext.RequestContext);
var href = "#";
if (!string.IsNullOrEmpty(actionName))
{
href = url.Action(actionName, controllerName);
}
linkTag.Attributes.Add("href", href);
linkTag.InnerHtml = string.Format("{0} {1}", iTag.ToString(TagRenderMode.Normal), linkText);
return MvcHtmlString.Create(linkTag.ToString(TagRenderMode.Normal));
}
示例2: GetUrl
/// <summary>
/// 获取导航Url
/// </summary>
/// <param name="presentAreaNavigation">被扩展的navigation</param>
/// <param name="spaceKey">空间标识</param>
/// <param name="routeValueDictionary">路由数据集合</param>
/// <returns></returns>
public static string GetUrl(this PresentAreaNavigation presentAreaNavigation, string spaceKey, RouteValueDictionary routeValueDictionary = null)
{
RouteValueDictionary routeDatas = null;
if (!string.IsNullOrEmpty(presentAreaNavigation.UrlRouteName))
{
if (!string.IsNullOrEmpty(presentAreaNavigation.RouteDataName) && routeValueDictionary != null)
{
string[] routeNames = presentAreaNavigation.RouteDataName.Split(',');
routeDatas = new RouteValueDictionary(routeValueDictionary.Where(n => routeNames.Contains(n.Key)).ToDictionary(n => n.Key, n => n.Value));
if (!routeNames.Contains("userName") && !routeNames.Contains("spaceKey"))
{
routeDatas.AddOrReplace("sapceKey", spaceKey);
}
}
else
routeDatas = new RouteValueDictionary() { { "spaceKey", spaceKey } };
return CachedUrlHelper.RouteUrl(presentAreaNavigation.UrlRouteName, routeDatas);
}
if (presentAreaNavigation.NavigationUrl != null && !string.IsNullOrEmpty(presentAreaNavigation.NavigationUrl.Trim()))
{
return presentAreaNavigation.NavigationUrl;
}
return string.Empty;
}
示例3: GenerateUrlToken
public static string GenerateUrlToken(string controllerName, string actionName, RouteValueDictionary argumentParams, string password)
{
//// The URL hash is dynamic by assign a dynamic key in each session. So
//// eventhough your URL is stolen, it will not work in other session
if (HttpContext.Current.Session["url_dynamickey"] == null)
{
HttpContext.Current.Session["url_dynamickey"] = RandomString();
}
// The salt include the dynamic session key and valid for an hour.
var salt = HttpContext.Current.Session["url_dynamickey"] + DateTime.Now.ToShortDateString() + " " + DateTime.Now.Hour;
// generating the partial url
var stringToToken = controllerName + "/" + actionName + "/";
stringToToken = argumentParams.Where(item => item.Key != "controller" && item.Key != "action" && item.Key != "urltoken").Aggregate(stringToToken, (current, item) => current + (item.Value));
// Converting the salt in to a byte array
var saltValueBytes = System.Text.Encoding.ASCII.GetBytes(salt);
// Encrypt the salt bytes with the password
var key = new Rfc2898DeriveBytes(password, saltValueBytes);
// get the key bytes from the above process
var secretKey = key.GetBytes(16);
// generate the hash
var tokenHash = new HMACSHA1(secretKey);
tokenHash.ComputeHash(System.Text.Encoding.ASCII.GetBytes(stringToToken));
// convert the hash to a base64string
var token = Convert.ToBase64String(tokenHash.Hash).Replace("/", "_");
return token;
}
示例4: SameRoute
/// <summary>
/// Helper to check if two RouteValueDictionaries have the same values
/// </summary>
private static bool SameRoute(RouteValueDictionary target, RouteValueDictionary routeValueDictionary)
{
var matches = target
.Where(pair => routeValueDictionary.ContainsKey(pair.Key) && Equals(pair.Value, routeValueDictionary[pair.Key]))
.Select(pair => pair.Key);
var mismatches = routeValueDictionary.Keys.Except(matches);
return !mismatches.Any();
}
示例5: GenerateKey
public string GenerateKey(ControllerContext context, CacheSettings cacheSettings)
{
var actionName = context.RouteData.Values["action"].ToString();
var controllerName = context.RouteData.Values["controller"].ToString();
// remove controller, action and DictionaryValueProvider which is added by the framework for child actions
var filteredRouteData = context.RouteData.Values.Where(x => x.Key.ToLowerInvariant() != "controller" &&
x.Key.ToLowerInvariant() != "action" &&
!(x.Value is DictionaryValueProvider<object>));
var routeValues = new RouteValueDictionary(filteredRouteData.ToDictionary(x => x.Key.ToLowerInvariant(), x => x.Value));
if (!context.IsChildAction)
{
// note that route values take priority over form values and form values take priority over query string values
foreach (var formKey in context.HttpContext.Request.Form.AllKeys)
{
if (!routeValues.ContainsKey(formKey.ToLowerInvariant()))
{
routeValues.Add(formKey.ToLowerInvariant(),
context.HttpContext.Request.Form[formKey].ToLowerInvariant());
}
}
foreach (var queryStringKey in context.HttpContext.Request.QueryString.AllKeys)
{
// queryStringKey is null if url has qs name without value. e.g. test.com?q
if (queryStringKey != null && !routeValues.ContainsKey(queryStringKey.ToLowerInvariant()))
{
routeValues.Add(queryStringKey.ToLowerInvariant(),
context.HttpContext.Request.QueryString[queryStringKey].ToLowerInvariant());
}
}
}
if (!string.IsNullOrEmpty(cacheSettings.VaryByParam))
{
if (cacheSettings.VaryByParam.ToLowerInvariant() == "none")
{
routeValues.Clear();
}
else if (cacheSettings.VaryByParam != "*")
{
var parameters = cacheSettings.VaryByParam.ToLowerInvariant().Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
routeValues = new RouteValueDictionary(routeValues.Where(x => parameters.Contains(x.Key)).ToDictionary(x => x.Key, x => x.Value));
}
}
if (!string.IsNullOrEmpty(cacheSettings.VaryByCustom))
{
routeValues.Add(cacheSettings.VaryByCustom.ToLowerInvariant(), context.HttpContext.ApplicationInstance.GetVaryByCustomString(HttpContext.Current, cacheSettings.VaryByCustom));
}
var key = _keyBuilder.BuildKey(controllerName, actionName, routeValues);
return key;
}
示例6: ProcessConstraints
/// <summary>
/// Process the constraints of the specified route
/// </summary>
/// <param name="constraints">Constraints to process</param>
/// <param name="routeInfo">Output information about the route</param>
public void ProcessConstraints(RouteValueDictionary constraints, RouteInfo routeInfo)
{
Contract.Requires(routeInfo.Constraints != null);
// Only add strings to the route info
var supportedConstraints = constraints.Where(constraint => constraint.Value is string);
foreach (var kvp in supportedConstraints)
{
routeInfo.Constraints.Add(kvp.Key, kvp.Value);
}
}
示例7: GetUrl
/// <summary>
/// 获取快捷操作Url
/// </summary>
/// <param name="applicationManagementOperation">被扩展的applicationManagementOperation</param>
/// <param name="routeValueDictionary">路由数据字典</param>
/// <returns></returns>
public static string GetUrl(this ApplicationManagementOperation applicationManagementOperation, RouteValueDictionary routeValueDictionary = null)
{
if (applicationManagementOperation.NavigationUrl != null && !string.IsNullOrEmpty(applicationManagementOperation.NavigationUrl.Trim()))
{
return applicationManagementOperation.NavigationUrl;
}
if (!string.IsNullOrEmpty(applicationManagementOperation.RouteDataName) && routeValueDictionary != null)
{
string[] routeNames = applicationManagementOperation.RouteDataName.Split(',');
RouteValueDictionary dic = new RouteValueDictionary(routeValueDictionary.Where(n => routeNames.Contains(n.Key)).ToDictionary(n => n.Key, n => n.Value));
return CachedUrlHelper.RouteUrl(applicationManagementOperation.UrlRouteName, dic);
}
return CachedUrlHelper.RouteUrl(applicationManagementOperation.UrlRouteName);
}
示例8: GetUrl
/// <summary>
/// 获取导航Url
/// </summary>
/// <param name="navigation">被扩展的navigation</param>
/// <param name="routeValueDictionary">路由数据集合</param>
/// <returns></returns>
public static string GetUrl(this Navigation navigation, RouteValueDictionary routeValueDictionary = null)
{
if (!string.IsNullOrEmpty(navigation.UrlRouteName))
{
if (!string.IsNullOrEmpty(navigation.RouteDataName) && routeValueDictionary != null)
{
string[] routeNames = navigation.RouteDataName.Split(',');
return CachedUrlHelper.RouteUrl(navigation.UrlRouteName, new RouteValueDictionary(routeValueDictionary.Where(n => routeNames.Contains(n.Key)).ToDictionary(n => n.Key, n => n.Value)));
}
return CachedUrlHelper.RouteUrl(navigation.UrlRouteName);
}
if (navigation.NavigationUrl != null && !string.IsNullOrEmpty(navigation.NavigationUrl.Trim()))
{
return navigation.NavigationUrl;
}
return string.Empty;
}
示例9: Current
/// <summary>
/// Returns current url modified by parameters
/// </summary>
/// <remarks>
/// Removes keyless query string values
/// </remarks>
/// <param name="context">Relevant request context</param>
/// <param name="with">Values to add or override</param>
/// <param name="without">Values to remove if present</param>
/// <returns>Route values</returns>
public static RouteValueDictionary Current(RequestContext context, RouteValueDictionary with, string[] without)
{
with = with ?? new RouteValueDictionary();
without = without ?? new string[0];
var result = new RouteValueDictionary();
var queryString = context.HttpContext.Request.QueryString;
foreach (var key in queryString.AllKeys.Where(k => k != null && !IgnoreValues.Contains(k) && !IsGuid.IsMatch(k) && !without.Contains(k)))
result[key] = queryString[key];
var routeValues = context.RouteData.Values;
foreach (var pair in routeValues.Where(p => !IgnoreValues.Contains(p.Key) && !IsGuid.IsMatch(p.Key) && !without.Contains(p.Key)))
result[pair.Key] = pair.Value;
foreach (var pair in with.Where(p => !IgnoreValues.Contains(p.Key) && !IsGuid.IsMatch(p.Key) && !without.Contains(p.Key)))
result[pair.Key] = pair.Value;
return result;
}
示例10: TokenizeRouteValues
private static void TokenizeRouteValues(RouteValueDictionary routeValues)
{
var tokenizedRouteValues = routeValues
.Where(i => i.Value != null)
.Select(i => new {i.Key, Value = i.Value.ToString()})
.Where(i => i.Value.StartsWith("${") && i.Value.EndsWith("}"))
.ToDictionary(
i => i.Key,
i => (object) new Token(i.Value));
foreach (var item in tokenizedRouteValues)
routeValues[item.Key] = item.Value;
}
示例11: GetVirtualPath
/// <summary>
/// Returns information about the URL that is associated with the route.
/// </summary>
/// <param name="requestContext">An object that encapsulates information about the requested route.</param>
/// <param name="values">An object that contains the parameters for a route.</param>
/// <returns>
/// An object that contains information about the URL that is associated with the route.
/// </returns>
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
if (requestContext == null)
{
throw new ArgumentNullException("requestContext");
}
// create new route data and include only non-excluded values
RouteData excludedRouteData = new RouteData(this, this.RouteHandler);
// add route values
requestContext.RouteData.Values
.Where(pair => !this.ExcludedRouteValuesNames.Contains(pair.Key, StringComparer.OrdinalIgnoreCase))
.ToList()
.ForEach(pair => excludedRouteData.Values.Add(pair.Key, pair.Value));
// add data tokens
requestContext.RouteData.DataTokens
.ToList()
.ForEach(pair => excludedRouteData.DataTokens.Add(pair.Key, pair.Value));
// intermediary request context
RequestContext currentContext = new RequestContext(new HttpContextWrapper(HttpContext.Current), excludedRouteData);
// create new URL route values and include only none-excluded values
RouteValueDictionary excludedRouteValues = new RouteValueDictionary(
values
.Where(v => !this.ExcludedRouteValuesNames.Contains(v.Key, StringComparer.OrdinalIgnoreCase))
.ToDictionary(pair => pair.Key, pair => pair.Value)
);
VirtualPathData result = base.GetVirtualPath(currentContext, excludedRouteValues);
return result;
}
示例12: GetVirtualPath
/// <summary>
/// Returns information about the URL that is associated with the route.
/// </summary>
/// <param name="requestContext">An object that encapsulates information about the requested route.</param>
/// <param name="values">An object that contains the parameters for a route.</param>
/// <returns>
/// An object that contains information about the URL that is associated with the route.
/// </returns>
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
if (KarbonWebContext.Current == null)
return null;
// Grab the model from the route data collection
var model = KarbonWebContext.Current.CurrentPage;
if (model == null)
return null;
// Create virtual path from model url
var vpd = new VirtualPathData(this, model.RelativeUrl.TrimStart("~/"));
// Append any other route data values as querystring params
var queryParams = values.Where(kvp => !kvp.Key.Equals(ControllerKey)
&& !kvp.Key.Equals(ActionKey))
.ToQueryString();
vpd.VirtualPath += queryParams;
// Return the virtual path
return vpd;
}
示例13: GenerateKey
public string GenerateKey(ControllerContext context, CacheSettings cacheSettings)
{
var routeData = context.RouteData;
if (routeData == null)
{
return null;
}
string actionName = null,
controllerName = null;
if (
routeData.Values.ContainsKey(RouteDataKeyAction) &&
routeData.Values[RouteDataKeyAction] != null)
{
actionName = routeData.Values[RouteDataKeyAction].ToString();
}
if (
routeData.Values.ContainsKey(RouteDataKeyController) &&
routeData.Values[RouteDataKeyController] != null)
{
controllerName = routeData.Values[RouteDataKeyController].ToString();
}
if (string.IsNullOrEmpty(actionName) || string.IsNullOrEmpty(controllerName))
{
return null;
}
string areaName = null;
if (routeData.DataTokens.ContainsKey(DataTokensKeyArea))
{
areaName = routeData.DataTokens[DataTokensKeyArea].ToString();
}
// remove controller, action and DictionaryValueProvider which is added by the framework for child actions
var filteredRouteData = routeData.Values.Where(
x => x.Key.ToLowerInvariant() != RouteDataKeyController &&
x.Key.ToLowerInvariant() != RouteDataKeyAction &&
x.Key.ToLowerInvariant() != DataTokensKeyArea &&
!(x.Value is DictionaryValueProvider<object>)
).ToList();
if (!string.IsNullOrWhiteSpace(areaName))
{
filteredRouteData.Add(new KeyValuePair<string, object>(DataTokensKeyArea, areaName));
}
var routeValues = new RouteValueDictionary(filteredRouteData.ToDictionary(x => x.Key.ToLowerInvariant(), x => x.Value));
if (!context.IsChildAction)
{
// note that route values take priority over form values and form values take priority over query string values
if ((cacheSettings.Options & OutputCacheOptions.IgnoreFormData) != OutputCacheOptions.IgnoreFormData)
{
foreach (var formKey in context.HttpContext.Request.Form.AllKeys)
{
if (routeValues.ContainsKey(formKey.ToLowerInvariant()))
{
continue;
}
var item = context.HttpContext.Request.Form[formKey];
routeValues.Add(
formKey.ToLowerInvariant(),
item != null
? item.ToLowerInvariant()
: string.Empty
);
}
}
if ((cacheSettings.Options & OutputCacheOptions.IgnoreQueryString) != OutputCacheOptions.IgnoreQueryString)
{
foreach (var queryStringKey in context.HttpContext.Request.QueryString.AllKeys)
{
// queryStringKey is null if url has qs name without value. e.g. test.com?q
if (queryStringKey == null || routeValues.ContainsKey(queryStringKey.ToLowerInvariant()))
{
continue;
}
var item = context.HttpContext.Request.QueryString[queryStringKey];
routeValues.Add(
queryStringKey.ToLowerInvariant(),
item != null
? item.ToLowerInvariant()
: string.Empty
);
}
}
}
if (!string.IsNullOrEmpty(cacheSettings.VaryByParam))
{
if (cacheSettings.VaryByParam.ToLowerInvariant() == "none")
//.........这里部分代码省略.........
示例14: GetVirtualPath
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
var usedValues = new List<string> { "_sitecoreitem" , "item" };
var item = values["_sitecoreitem"] as Item ?? values["item"] as Item;
var requestedPath = new string[0];
if (item == null)
{
var id = values["path"] ?? values["id"];
usedValues.Add(id == values["path"] ? "path" : "id");
if (id != null)
{
if (id is string && (id.ToString()).Contains("/"))
{
if (!(id.ToString()).StartsWith(Context.Site.RootPath))
id = Context.Site.RootPath + "/" + id.ToString().TrimStart('/');
requestedPath = id.ToString().Split(new[]{'/'}, StringSplitOptions.RemoveEmptyEntries);
}
if (id is ID)
{
item = (Context.Database ?? Context.ContentDatabase).GetItem((ID)id);
}
else
{
item = (Context.Database ?? Context.ContentDatabase).GetItem(id.ToString());
}
}
}
if (item != null)
{
var url = LinkManager.GetItemUrl(item);
url = VirtualPathUtility.ToAppRelative(url);
if (url.StartsWith("~/"))
url = url.Substring(2);
var urlparts = url.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
var wildcardItem = item;
var i = urlparts.Length - 1;
using (new SecurityDisabler())
{
while (wildcardItem != null && i >= 0)
{
if (wildcardItem.Name == "*" && wildcardItem.DisplayName.Length > 1)
{
string name = wildcardItem.DisplayName.TrimStart('*', '(', ' ').TrimEnd(')', ' ');
if (values.ContainsKey(name))
{
urlparts[i] = values[name] + "";
}
else
{
if (i < requestedPath.Length)
{
//requestedpath is always the full path!
urlparts[i] =
requestedPath[
wildcardItem.Paths.FullPath.Split(new[] {'/'},
StringSplitOptions.RemoveEmptyEntries).
Length - 1];
}
}
usedValues.Add(name.ToLower());
}
wildcardItem = wildcardItem.Parent;
i--;
}
}
var newurl = new StringBuilder(string.Join("/", urlparts));
var extension = Path.GetExtension(url);
if (!string.IsNullOrEmpty(extension) && !extension.Equals(Path.GetExtension(newurl.ToString())))
newurl.Append(extension);
// Add remaining new values as query string parameters to the URL
// Generate the query string
bool firstParam = !newurl.ToString().Contains("?");
var unusedValues = values.Where(v => !usedValues.Contains(v.Key.ToLower()));
foreach (var unusedValue in unusedValues)
{
newurl.Append(firstParam ? '?' : '&');
firstParam = false;
newurl.Append(Uri.EscapeDataString(unusedValue.Key));
newurl.Append('=');
newurl.Append(Uri.EscapeDataString(System.Convert.ToString(unusedValue.Value, CultureInfo.InvariantCulture)));
}
return new VirtualPathData(this, newurl.ToString());
}
return null;
}
示例15: ExtractContentPath
/// <summary>
/// Gets the content path from the route values
/// </summary>
private string ExtractContentPath(RouteValueDictionary values)
{
int ord;
string path = values
.Where(v => v.Key.StartsWith("_") && int.TryParse(v.Key.Substring(1).UpTo("-"), out ord))
.OrderBy(v => int.Parse(v.Key.Substring(1).UpTo("-")))
.Select(v => v.Value)
.Join("&");
return path;
}