本文整理汇总了C#中System.Web.Mvc.UrlHelper.SetQueryParameters方法的典型用法代码示例。如果您正苦于以下问题:C# UrlHelper.SetQueryParameters方法的具体用法?C# UrlHelper.SetQueryParameters怎么用?C# UrlHelper.SetQueryParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.UrlHelper
的用法示例。
在下文中一共展示了UrlHelper.SetQueryParameters方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnActionExecuting
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (_skipControllers.Any(x => filterContext.ActionDescriptor.ControllerDescriptor.ControllerType == x))
{
return;
}
var context = filterContext.HttpContext;
// don't 'rewrite' POST requests, child action and ajax requests
if (context.Request.RequestType != "GET" || filterContext.IsChildAction || context.Request.IsAjaxRequest())
{
return;
}
if (context.Request.Url != null)
{
var baseUri = string.Format(
"{0}://{1}{2}",
context.Request.Url.Scheme,
context.Request.Url.Host,
context.Request.Url.Port == 80 ? "" : ":" + context.Request.Url.Port);
var path = HttpUtility.UrlDecode(string.Concat(baseUri, context.Request.Url.AbsolutePath));
if (!string.IsNullOrEmpty(path))
{
var query = HttpUtility.UrlDecode(context.Request.Url.Query);
var queryString = context.Request.QueryString;
var needRedirect = false;
//Make sure we allways use same virtual path as Route provides
var routePath = filterContext.RouteData.Route.GetVirtualPath(filterContext.RequestContext,
filterContext.RouteData.Values);
if (routePath != null && !string.IsNullOrEmpty(routePath.VirtualPath))
{
var absoluteRoutePath = HttpUtility.UrlDecode(string.Concat(baseUri, context.Request.ApplicationPath, context.Request.ApplicationPath != "/" ? "/" : "", routePath.VirtualPath));
if (!string.IsNullOrEmpty(absoluteRoutePath) && !absoluteRoutePath.Equals(path, StringComparison.InvariantCultureIgnoreCase))
{
path = absoluteRoutePath;
needRedirect = true;
}
}
//Process query string
if (!string.IsNullOrEmpty(query))
{
//Rebuild querystring from scratch
var newQuery = string.Empty;
//First goes search filter ordered based on document
var helper = new SearchHelper(StoreHelper.StoreClient.GetCurrentStore());
var urlHelper = new UrlHelper(context.Request.RequestContext);
var parameters = helper.Filters.Where(f => !(f is PriceRangeFilter) || ((PriceRangeFilter)f).Currency.Equals(StoreHelper.CustomerSession.Currency, StringComparison.OrdinalIgnoreCase))
.Select(filter => queryString.AllKeys
.FirstOrDefault(k => k.Equals(urlHelper.GetFacetKey(filter.Key), StringComparison.InvariantCultureIgnoreCase)))
.Where(key => !string.IsNullOrEmpty(key))
.ToDictionary<string, string, object>(key => key, key => queryString[key]);
if (parameters.Any())
{
newQuery = urlHelper.SetQueryParameters(newQuery, parameters);
}
//Order remaining parameters
var otherParams = queryString.AllKeys.Where(key => !parameters.ContainsKey(key)).OrderBy(k => k)
.ToDictionary<string, string, object>(key => key, key => queryString[key]);
if (otherParams.Any())
{
newQuery = urlHelper.SetQueryParameters(newQuery, otherParams);
}
if (!string.IsNullOrEmpty(newQuery) && !newQuery.StartsWith("?"))
{
newQuery = string.Concat("?", newQuery);
}
newQuery = HttpUtility.UrlDecode(newQuery);
if (!string.Equals(query, newQuery, StringComparison.InvariantCultureIgnoreCase))
{
query = newQuery;
needRedirect = true;
}
}
//make language code allways be five symbols
if (filterContext.RouteData.Values.ContainsKey(Routing.Constants.Language) &&
filterContext.RouteData.Values[Routing.Constants.Language] as string != null)
{
var lang = filterContext.RouteData.Values[Routing.Constants.Language].ToString();
if (lang.Length < 5)
{
try
{
var cult = CultureInfo.CreateSpecificCulture(lang);
//.........这里部分代码省略.........