本文整理汇总了C#中RouteValueDictionary.ContainsKey方法的典型用法代码示例。如果您正苦于以下问题:C# RouteValueDictionary.ContainsKey方法的具体用法?C# RouteValueDictionary.ContainsKey怎么用?C# RouteValueDictionary.ContainsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RouteValueDictionary
的用法示例。
在下文中一共展示了RouteValueDictionary.ContainsKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetVirtualPath
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values) {
VirtualPathData result = null;
if (values.ContainsKey("legacyURL") && urls.Contains((string)values["legacyURL"], StringComparer.OrdinalIgnoreCase)) {
result = new VirtualPathData(this, new UrlHelper(requestContext).Content((string)values["legacyURL"]).Substring(1));
}
return result;
}
示例2: GetRouteValues
/// <summary>Gets route data for for items this route handles.</summary>
/// <param name="item">The item whose route to get.</param>
/// <param name="routeValues">The route values to apply to the route data.</param>
/// <returns>A route data object or null.</returns>
public virtual RouteValueDictionary GetRouteValues(ContentItem item, RouteValueDictionary routeValues)
{
string actionName = "Index";
if (routeValues.ContainsKey(ActionKey))
actionName = (string)routeValues[ActionKey];
string id = null;
if (routeValues.ContainsKey(IdKey))
id = (string)routeValues[IdKey];
string controllerName = controllerMapper.GetControllerName(item.GetContentType());
if (controllerName == null || !controllerMapper.ControllerHasAction(controllerName, actionName))
return null;
var values = new RouteValueDictionary(routeValues);
foreach (var kvp in innerRoute.Defaults)
if(!values.ContainsKey(kvp.Key))
values[kvp.Key] = kvp.Value;
values[ControllerKey] = controllerName;
values[ActionKey] = actionName;
values[ContentItemKey] = item.ID;
values[AreaKey] = innerRoute.DataTokens["area"];
if (!string.IsNullOrEmpty(id))
{
values[IdKey] = id;
}
return values;
}
示例3: IsMatch
protected override bool IsMatch(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
if (!base.IsMatch(httpContext, route, parameterName, values, routeDirection))
{
return false;
}
if (routeDirection == RouteDirection.UrlGeneration)
{
return true;
}
var encoded = values[parameterName].ToString();
var decoded = SettingsHelper.SeoDecode(encoded, SeoUrlKeywordTypes.Item, values.ContainsKey(Constants.Language) ? values[Constants.Language] as string : null);
var item = CartHelper.CatalogClient.GetItem(decoded, bycode: true);
if (item == null)
{
return false;
}
//Check if category is correct
if (values.ContainsKey(Constants.Category))
{
encoded = values[Constants.Category].ToString();
decoded = SettingsHelper.SeoDecode(encoded, SeoUrlKeywordTypes.Category, values.ContainsKey(Constants.Language) ? values[Constants.Language].ToString() : null);
//Todo mark valid outline somehow
return item.GetItemCategoryBrowsingOutlines().Any(outline => ValidateCategoryPath(outline, decoded));
}
return true;
}
示例4: GenerateTab
public string GenerateTab(ref HtmlHelper html, string text, string value)
{
var routeDataValues = html.ViewContext.RequestContext.RouteData.Values;
RouteValueDictionary pageLinkValueDictionary = new RouteValueDictionary { { Param, value } };
if (html.ViewContext.RequestContext.HttpContext.Request.QueryString["search"] != null)
pageLinkValueDictionary.Add("search", html.ViewContext.RequestContext.HttpContext.Request.QueryString["search"]);
if (!pageLinkValueDictionary.ContainsKey("id") && routeDataValues.ContainsKey("id"))
pageLinkValueDictionary.Add("id", routeDataValues["id"]);
// To be sure we get the right route, ensure the controller and action are specified.
if (!pageLinkValueDictionary.ContainsKey("controller") && routeDataValues.ContainsKey("controller"))
pageLinkValueDictionary.Add("controller", routeDataValues["controller"]);
if (!pageLinkValueDictionary.ContainsKey("action") && routeDataValues.ContainsKey("action"))
pageLinkValueDictionary.Add("action", routeDataValues["action"]);
// 'Render' virtual path.
var virtualPathForArea = RouteTable.Routes.GetVirtualPathForArea(html.ViewContext.RequestContext, pageLinkValueDictionary);
if (virtualPathForArea == null)
return null;
var stringBuilder = new StringBuilder("<li");
if (value == CurrentValue)
stringBuilder.Append(" class=active");
stringBuilder.AppendFormat("><a href={0}>{1}</a></li>", virtualPathForArea.VirtualPath, text);
return stringBuilder.ToString();
}
示例5: GetVirtualPath
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
//判断请求是否来源于CatalogController.ShowDesigns(string no),不是则返回null,让匹配继续
var catalogNo = values["no"] as string;
if (catalogNo == null)//路由信息中缺少参数no,不是我们要处理的请求,返回null
return null;
//请求不是CatalogController发起的,不是我们要处理的请求,返回null
if (!values.ContainsKey("controller") || !values["controller"].ToString().Equals("category", StringComparison.OrdinalIgnoreCase))
return null;
//请求不是CatalogController.ShowDesigns(string no)发起的,不是我们要处理的请求,返回null
if (!values.ContainsKey("action") || !values["action"].ToString().Equals("showdesigns", StringComparison.OrdinalIgnoreCase))
return null;
//至此,我们可以确定请求是CatalogController.ShowDesigns(string no)发起的,生成相应的URL并返回
var catalog = CatalogManager.AllCategories.Find(c => c.CatalogNo == catalogNo);
if (catalog == null)
throw new ArgumentNullException("design");//找不到分类抛出异常
var path = "ca-" + catalog.CatalogName.Trim();//生成URL
return new VirtualPathData(this, path.ToLowerInvariant());
}
示例6: 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;
}
示例7: LanguageDropDown
public static HtmlString LanguageDropDown(this HtmlHelper htmlhelper, RouteValueDictionary arguments)
{
var langs = arguments.ContainsKey("languages") ? (Dictionary<string, string>)arguments["languages"] : new Dictionary<string, string>();
var id = arguments.ContainsKey("id") ? (string)arguments["id"] : null;
var selectedLang = arguments.ContainsKey("selectedLanguage") ? (string)arguments["selectedLanguage"] : "";
var disabled = arguments.ContainsKey("isDisabled") ? (bool)arguments["isDisabled"] : false;
return LanguageDropDownHelper(htmlhelper, langs, id, selectedLang, disabled);
}
示例8: GetVirtualPath
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
if (values.ContainsKey("controller") && (!string.Equals(Controller, values["controller"] as string, StringComparison.InvariantCultureIgnoreCase)))
return null;
if (values.ContainsKey("action") && (!string.Equals(Action, values["action"] as string, StringComparison.InvariantCultureIgnoreCase)))
return null;
if ( (!values.ContainsKey("id")) || (!values.ContainsKey("title")) || (!values.ContainsKey("culture")) )
return null;
return new VirtualPathData(this, string.Format("{0}/{1}-{2}.html", values["culture"], values["id"], values["title"]));
}
示例9: PageUrl
private static string PageUrl(this UrlHelper urlHelper, PageReference pageLink, object routeValues, IContentLoader contentQueryable, IPermanentLinkMapper permanentLinkMapper, LanguageSelectorFactory languageSelectorFactory)
{
RouteValueDictionary routeValueDictionary = new RouteValueDictionary(routeValues);
if (!routeValueDictionary.ContainsKey(RoutingConstants.LanguageKey))
routeValueDictionary[RoutingConstants.LanguageKey] = (object)ContentLanguage.PreferredCulture.Name;
if (!routeValueDictionary.ContainsKey(RoutingConstants.ActionKey))
routeValueDictionary[RoutingConstants.ActionKey] = (object)"index";
routeValueDictionary[RoutingConstants.NodeKey] = (object)pageLink;
UrlExtensions.SetAdditionalContextValuesForContent(urlHelper, pageLink, routeValueDictionary, contentQueryable, permanentLinkMapper, languageSelectorFactory);
return urlHelper.Action(null, routeValueDictionary);
}
示例10: Match
public virtual bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
if(values.ContainsKey("mediaId") && values["mediaId"].ToString().IsGuid(false)
&& values.ContainsKey("fileName") && values["fileName"] != null && !values["fileName"].ToString().IsNullOrWhiteSpace())
{
// TODO: Media ID is a guid and we have a filename so check the Hive for a valid file
return true;
}
return false;
}
示例11: GetVirtualPath
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
if ((values.ContainsKey(Consts.RouteServiceKey) || requestContext.RouteData.DataTokens.ContainsKey(Consts.RouteServiceKey)) && !values.ContainsKey(Consts.RouteExternalService))
return null;
var tmpValues = new RouteValueDictionary(values);
tmpValues.Remove(Consts.RouteServiceKey);
tmpValues.Remove(Consts.RouteExternalService);
return base.GetVirtualPath(requestContext, tmpValues);
}
示例12: Match
public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection)
{
if (routeDirection == RouteDirection.UrlGeneration)
return false;
if (values.ContainsKey("controller") || values.ContainsKey("action"))
return false;
if (route.Url.StartsWith(_settings.AttachmentsRoutePath +"/{*filename}"))
return true;
else
return false;
}
示例13: ChangePassword
public ActionResult ChangePassword(ChangePasswordModel model)
{
if (ModelState.IsValid)
{
MembershipUser user = Membership.GetUser(model.UserName);
if (user != null)
{
bool success = ViewBag.success = false;
RouteValueDictionary routes = new RouteValueDictionary();
routes.Add("user", model.UserName);
try
{
success = user.ChangePassword(model.CurrentPassword, model.NewPassword);
}
catch (PreviouslyUsedPasswordException)
{
routes.Add("statusMessage", "Your Password was not changed, please enter a new password that does not match any of the previous passwords you have used for the last 252 days.");
}
catch (ArgumentException)
{
if (!routes.ContainsKey("statusMessage"))
{
routes.Add("statusMessage", "Your Password was not changed. Please check that the current password you have entered is correct, and enter a new password that contains a capital letter, a number, a special character, and is at least 8 characters in length.");
}
}
if (success && !routes.ContainsKey("statusMessage"))
{
routes.Add("statusMessage", "Your Password has been successfully changed.");
}
else if (!routes.ContainsKey("statusMessage"))
{
routes.Add("statusMessage", "Your Password was not changed, please check that the current password you have entered is correct.");
}
if (Request.IsAuthenticated)
return RedirectToAction("PasswordChangeConfirm", "Users", routes);
else
{
RouteValueDictionary routs = new RouteValueDictionary();
routs.Add("returnUrl", null);
return RedirectToAction("Login", "Users", routs);
}
}
else return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError(model.UserName, "ModelState is not valid");
return View(model);
}
}
示例14: Register
public void Register(string title, string format, RouteValueDictionary values) {
var link = new RouteValueDictionary(values) { { "format", format } };
if (!link.ContainsKey("area")) {
link["area"] = "Feeds";
}
if (!link.ContainsKey("controller")) {
link["controller"] = "Feed";
}
if (!link.ContainsKey("action")) {
link["action"] = "Index";
}
_links.Add(new Link { Title = title, RouteValues = link });
}
示例15: PagingLinks
public static MvcHtmlString PagingLinks(this HtmlHelper helper, int totalPages, string currentPageUrlParameter = "pagenumber")
{
RouteData routeData = helper.ViewContext.RouteData;
string actionName = routeData.GetRequiredString("action");
string controllerName = routeData.GetRequiredString("controller");
RouteValueDictionary routeValues = new RouteValueDictionary(routeData.Values);
int currentPage = 1;
if (routeValues.ContainsKey(currentPageUrlParameter))
{
// Pagenumber is present in RouteValues
Int32.TryParse(Convert.ToString(routeValues[currentPageUrlParameter]), out currentPage);
}
else if (!String.IsNullOrEmpty(helper.ViewContext.HttpContext.Request.QueryString[currentPageUrlParameter]))
{
// Pagenumber is present in QueryString
Int32.TryParse(helper.ViewContext.HttpContext.Request.QueryString[currentPageUrlParameter], out currentPage);
}
// Add all values from the QueryString to the RouteValues so they are preserved in the pagelinks
foreach (var key in helper.ViewContext.HttpContext.Request.QueryString.AllKeys)
{
if (!routeValues.ContainsKey(key)) routeValues.Add(key, helper.ViewContext.HttpContext.Request.QueryString[key]);
}
// Get the different items ("previous", "next", pagenumbers, "...") that need to be rendered
var pageItems = GenerateLinkItems(currentPage, totalPages);
StringBuilder pagerCode = new StringBuilder();
pagerCode.Append(@"<div class=""pager"">");
foreach (var pageItem in pageItems)
{
if (pageItem.IsLink)
{
routeValues[currentPageUrlParameter] = pageItem.Pagenumber;
pagerCode.Append(helper.ActionLink(pageItem.Text, actionName, controllerName, routeValues, new Dictionary<string, object> { { "class", pageItem.CssClass } }));
}
else
{
TagBuilder span = new TagBuilder("span");
span.AddCssClass(pageItem.CssClass);
span.SetInnerText(pageItem.Text);
pagerCode.Append(span.ToString());
}
}
pagerCode.Append("</div>");
return MvcHtmlString.Create(pagerCode.ToString());
}