本文整理汇总了C#中HttpRouteValueDictionary类的典型用法代码示例。如果您正苦于以下问题:C# HttpRouteValueDictionary类的具体用法?C# HttpRouteValueDictionary怎么用?C# HttpRouteValueDictionary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpRouteValueDictionary类属于命名空间,在下文中一共展示了HttpRouteValueDictionary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MapODataRoute
/// <summary>
/// Map odata route with query string or header constraints
/// </summary>
public static void MapODataRoute(
this HttpRouteCollection routes,
string routeName,
string routePrefix,
IEdmModel model,
IODataPathHandler pathHandler,
IEnumerable<IODataRoutingConvention> routingConventions,
object queryConstraints,
object headerConstraints)
{
if (routes == null)
{
throw new ArgumentNullException("routes");
}
string routeTemplate = string.IsNullOrEmpty(routePrefix) ? ODataRouteConstants.ODataPathTemplate : (routePrefix + "/" + ODataRouteConstants.ODataPathTemplate);
ODataVersionRouteConstraint routeConstraint = new ODataVersionRouteConstraint(pathHandler, model, routeName, routingConventions, queryConstraints, headerConstraints);
var constraints = new HttpRouteValueDictionary();
constraints.Add(ODataRouteConstants.ConstraintName, routeConstraint);
routes.MapHttpRoute(
routeName,
routeTemplate,
defaults: null,
constraints: constraints);
}
示例2: Register
public static void Register(HttpConfiguration config)
{
// Web API 配置和服务
// Web API 路由
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }//,
//constraints:new{sss=new HttpMethodConstraint(HttpMethod.Post)}
);
HttpRouteValueDictionary defaults = new HttpRouteValueDictionary();
//defaults.Add("controller", "Demo");
//defaults.Add("action", "Get");
defaults.Add("val", 0);
HttpRouteValueDictionary constraints = new HttpRouteValueDictionary();
constraints.Add("val",new DoubleRouteConstraint());
HttpRoute route = new HttpRoute("customer/{controller}/{action}/{val}", defaults, constraints);
config.Routes.Add("CustomerApi",route);
}
示例3: Register
public static void Register(HttpConfiguration config)
{
var emptyDictionary = new HttpRouteValueDictionary();
// Add our one HttpMessageHandler to the root path.
config.Routes.MapHttpRoute("index", "", emptyDictionary, emptyDictionary,
new HelloWorldHandler());
}
示例4: BuildHttpRoute
/// <summary>
/// Builds an <see cref="IHttpRoute"/>.
/// </summary>
/// <param name="routeTemplate">The detokenized route template.</param>
/// <param name="defaults">The route defaults.</param>
/// <param name="constraints">The route constraints.</param>
/// <param name="actions">The actions to invoke for the route.</param>
/// <returns>The generated <see cref="IHttpRoute"/>.</returns>
public virtual IHttpRoute BuildHttpRoute(
string routeTemplate,
HttpRouteValueDictionary defaults,
HttpRouteValueDictionary constraints,
IEnumerable<ReflectedHttpActionDescriptor> actions)
{
return new HttpDirectRoute(routeTemplate, defaults, constraints, actions);
}
示例5: HttpAttributeRoute
/// <summary>
/// Route used by the AttributeRouting framework in self-host projects.
/// </summary>
public HttpAttributeRoute(string url,
HttpRouteValueDictionary defaults,
HttpRouteValueDictionary constraints,
HttpRouteValueDictionary dataTokens,
HttpAttributeRoutingConfiguration configuration)
: base(url, defaults, constraints, dataTokens)
{
_configuration = configuration;
}
示例6: ODataVersionRouteConstraint
public ODataVersionRouteConstraint(
string routeName,
object queryConstraints,
object headerConstraints)
: base(routeName)
{
QueryStringConstraints = new HttpRouteValueDictionary(queryConstraints);
HeaderConstraints = new HttpRouteValueDictionary(headerConstraints);
}
示例7: HttpAttributeRoute
/// <summary>
/// Route used by the AttributeRouting framework in self-host projects.
/// </summary>
public HttpAttributeRoute(string url,
HttpRouteValueDictionary defaults,
HttpRouteValueDictionary constraints,
HttpRouteValueDictionary dataTokens,
HttpConfigurationBase configuration)
: base(url, defaults, constraints, dataTokens, configuration.MessageHandler)
{
_configuration = configuration;
}
示例8: GetPrecedence
private static decimal GetPrecedence(string attributeRouteTemplate)
{
DefaultInlineConstraintResolver resolver = new DefaultInlineConstraintResolver();
HttpRouteValueDictionary defaults = new HttpRouteValueDictionary();
HttpRouteValueDictionary constraints = new HttpRouteValueDictionary();
string standardRouteTemplate = InlineRouteTemplateParser.ParseRouteTemplate(attributeRouteTemplate,
defaults, constraints, new DefaultInlineConstraintResolver());
HttpParsedRoute parsedRoute = HttpRouteParser.Parse(standardRouteTemplate);
return parsedRoute.GetPrecedence(constraints);
}
示例9: ODataRoute
/// <summary>
/// Initializes a new instance of the <see cref="ODataRoute" /> class.
/// </summary>
/// <param name="routePrefix">The route prefix.</param>
/// <param name="pathConstraint">The OData path constraint.</param>
/// <param name="defaults">The default values for the route.</param>
/// <param name="constraints">The route constraints.</param>
/// <param name="dataTokens">The data tokens.</param>
/// <param name="handler">The message handler for the route.</param>
public ODataRoute(
string routePrefix,
ODataPathRouteConstraint pathConstraint,
HttpRouteValueDictionary defaults,
HttpRouteValueDictionary constraints,
HttpRouteValueDictionary dataTokens,
HttpMessageHandler handler)
: this(routePrefix, (IHttpRouteConstraint)pathConstraint, defaults, constraints, dataTokens, handler)
{
}
示例10: HttpRoute
public HttpRoute(string routeTemplate, HttpRouteValueDictionary defaults, HttpRouteValueDictionary constraints, HttpRouteValueDictionary dataTokens)
{
_routeTemplate = String.IsNullOrWhiteSpace(routeTemplate) ? String.Empty : routeTemplate;
_defaults = defaults ?? new HttpRouteValueDictionary();
_constraints = constraints ?? new HttpRouteValueDictionary();
_dataTokens = dataTokens ?? new HttpRouteValueDictionary();
// The parser will throw for invalid routes.
_parsedRoute = HttpRouteParser.Parse(_routeTemplate);
}
示例11: TestValue
protected bool TestValue(IHttpRouteConstraint constraint, object value)
{
HttpRequestMessage httpRequestMessage = new HttpRequestMessage();
HttpRoute httpRoute = new HttpRoute();
const string parameterName = "fake";
HttpRouteValueDictionary values = new HttpRouteValueDictionary { { parameterName, value } };
const HttpRouteDirection httpRouteDirection = HttpRouteDirection.UriResolution;
return constraint.Match(httpRequestMessage, httpRoute, parameterName, values, httpRouteDirection);
}
示例12: MapHttpRoute
/// <summary>
///
/// </summary>
/// <param name="routes"></param>
/// <param name="name"></param>
/// <param name="routeTemplate"></param>
/// <param name="defaults"></param>
/// <param name="constraints"></param>
/// <param name="handler"></param>
/// <param name="namespaces"></param>
/// <returns></returns>
public static IHttpRoute MapHttpRoute(this HttpRouteCollection routes, string name, string routeTemplate, object defaults, object constraints, HttpMessageHandler handler, string[] namespaces)
{
if (routes == null)
{
throw new ArgumentNullException("routes");
}
var routeValue = new HttpRouteValueDictionary(new { Namespace = namespaces });//设置路由值
var route = routes.CreateRoute(routeTemplate, new HttpRouteValueDictionary(defaults), new HttpRouteValueDictionary(constraints), routeValue, handler);
routes.Add(name, route);
return route;
}
示例13: HttpRoute
public HttpRoute(string routeTemplate, HttpRouteValueDictionary defaults, HttpRouteValueDictionary constraints, HttpRouteValueDictionary dataTokens, HttpMessageHandler handler)
{
_routeTemplate = routeTemplate == null ? String.Empty : routeTemplate;
_defaults = defaults ?? new HttpRouteValueDictionary();
_constraints = constraints ?? new HttpRouteValueDictionary();
_dataTokens = dataTokens ?? new HttpRouteValueDictionary();
Handler = handler;
// The parser will throw for invalid routes.
ParsedRoute = HttpRouteParser.Parse(RouteTemplate);
}
示例14: Constructor_IsCaseInsensitive
public void Constructor_IsCaseInsensitive()
{
// Arrange
HttpRouteValueDictionary routeValues = new HttpRouteValueDictionary();
// Act
routeValues.Add("KEY", null);
// Assert
Assert.True(routeValues.ContainsKey("key"));
}
示例15: ODataVersionRouteConstraint
public ODataVersionRouteConstraint(
IODataPathHandler pathHandler,
IEdmModel model,
string routeName,
IEnumerable<IODataRoutingConvention> routingConventions,
object queryConstraints,
object headerConstraints)
: base(pathHandler, model, routeName, routingConventions)
{
QueryStringConstraints = new HttpRouteValueDictionary(queryConstraints);
HeaderConstraints = new HttpRouteValueDictionary(headerConstraints);
}