本文整理汇总了C#中IHttpRoute类的典型用法代码示例。如果您正苦于以下问题:C# IHttpRoute类的具体用法?C# IHttpRoute怎么用?C# IHttpRoute使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IHttpRoute类属于命名空间,在下文中一共展示了IHttpRoute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryAddRoute
public bool TryAddRoute(string routeName, string routeTemplate, IEnumerable<HttpMethod> methods, HttpRouteCollection routes, out IHttpRoute route)
{
route = null;
try
{
var routeBuilder = CreateRouteBuilder(routeTemplate);
var constraints = routeBuilder.Constraints;
if (methods != null)
{
// if the methods collection is not null, apply the constraint
// if the methods collection is empty, we'll create a constraint
// that disallows ALL methods
constraints.Add("httpMethod", new HttpMethodConstraint(methods.ToArray()));
}
route = routes.CreateRoute(routeBuilder.Template, routeBuilder.Defaults, constraints);
routes.Add(routeName, route);
}
catch (Exception ex) when (!ex.IsFatal())
{
// catch any route parsing errors
return false;
}
return true;
}
示例2: Match
public bool Match(HttpRequestMessage request,
IHttpRoute route,
string segmentPrefix,
IDictionary<string, object> values,
HttpRouteDirection routeDirection)
{
if (segmentPrefix == null)
{
throw new ArgumentNullException("segmentPrefix");
}
if (values == null)
{
throw new ArgumentNullException("values");
}
object value;
if (values.TryGetValue(segmentPrefix, out value))
{
string valueString = value as string;
return valueString != null
&& (valueString.StartsWith(segmentPrefix + ";", StringComparison.OrdinalIgnoreCase)
|| String.Equals(valueString, segmentPrefix, StringComparison.OrdinalIgnoreCase));
}
return false;
}
示例3: Match
public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName,
IDictionary<string, object> values, HttpRouteDirection routeDirection)
{
var versionFinder = new VersionFinder();
var version = versionFinder.GetVersionFromRequest(request);
return _version == version;
}
示例4: Match
/// <inheritdoc />
public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
{
if (parameterName == null)
{
throw Error.ArgumentNull("parameterName");
}
if (values == null)
{
throw Error.ArgumentNull("values");
}
object value;
if (values.TryGetValue(parameterName, out value) && value != null)
{
if (value is long)
{
return true;
}
long result;
string valueString = Convert.ToString(value, CultureInfo.InvariantCulture);
return Int64.TryParse(valueString, NumberStyles.Integer, CultureInfo.InvariantCulture, out result);
}
return false;
}
示例5: Match
public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName,
IDictionary<string, object> values, HttpRouteDirection routeDirection)
{
if (values == null)
{
return true;
}
if (!values.ContainsKey(parameterName) || !values.ContainsKey(Id))
{
return true;
}
string action = values[parameterName].ToString().ToLower();
if (string.IsNullOrEmpty(action))
{
values[parameterName] = request.Method.ToString();
}
else if (string.IsNullOrEmpty(values[Id].ToString()))
{
bool isAction = _array.All(item => action.StartsWith(item.ToLower()));
if (isAction)
{
return true;
}
//values[Id] = values[parameterName];
//values[parameterName] = request.Method.ToString();
}
return true;
}
示例6: ExploreRouteControllers
private void ExploreRouteControllers(IDictionary<string, HttpControllerDescriptor> controllerMappings, IHttpRoute route, Collection<ApiDescription> apiDescriptions)
{
string routeTemplate = route.RouteTemplate;
object controllerVariableValue;
if (_controllerVariableRegex.IsMatch(routeTemplate))
{
// unbound controller variable, {controller}
foreach (KeyValuePair<string, HttpControllerDescriptor> controllerMapping in controllerMappings)
{
controllerVariableValue = controllerMapping.Key;
HttpControllerDescriptor controllerDescriptor = controllerMapping.Value;
if (DefaultExplorer.ShouldExploreController(controllerVariableValue.ToString(), controllerDescriptor, route))
{
// expand {controller} variable
string expandedRouteTemplate = _controllerVariableRegex.Replace(routeTemplate, controllerVariableValue.ToString());
ExploreRouteActions(route, expandedRouteTemplate, controllerDescriptor, apiDescriptions);
}
}
}
else
{
// bound controller variable, {controller = "controllerName"}
if (route.Defaults.TryGetValue(ControllerVariableName, out controllerVariableValue))
{
HttpControllerDescriptor controllerDescriptor;
if (controllerMappings.TryGetValue(controllerVariableValue.ToString(), out controllerDescriptor) && DefaultExplorer.ShouldExploreController(controllerVariableValue.ToString(), controllerDescriptor, route))
{
ExploreRouteActions(route, routeTemplate, controllerDescriptor, apiDescriptions);
}
}
}
}
示例7: Match
public bool Match(
HttpRequestMessage request,
IHttpRoute route,
string parameterName,
IDictionary<string, object> values,
HttpRouteDirection routeDirection) =>
Match(parameterName, values);
示例8: Match
/// <inheritdoc />
public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
{
if (route == null)
{
throw Error.ArgumentNull("route");
}
if (parameterName == null)
{
throw Error.ArgumentNull("parameterName");
}
if (values == null)
{
throw Error.ArgumentNull("values");
}
// If the parameter is optional and has no value, then pass the constraint
object defaultValue;
if (route.Defaults.TryGetValue(parameterName, out defaultValue) && defaultValue == RouteParameter.Optional)
{
object value;
if (values.TryGetValue(parameterName, out value) && value == RouteParameter.Optional)
{
return true;
}
}
return InnerConstraint.Match(request, route, parameterName, values, routeDirection);
}
示例9: Match
protected override bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
{
if (routeDirection == HttpRouteDirection.UriGeneration)
return true;
return base.Match(request, route, parameterName, values, routeDirection);
}
示例10: Match
/// <inheritdoc />
public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName,
IDictionary<string, object> values, HttpRouteDirection routeDirection)
{
// The match behaviour depends on value of IsRelaxedMatch.
// If users select using relaxed match logic, the header contains both V3 (or before) and V4 style version
// will be regarded as valid. While under non-relaxed match logic, both version headers presented will be
// regarded as invalid. The behavior for other situations are the same. When non version headers present,
// assume using MaxVersion.
if (request == null)
{
throw Error.ArgumentNull("request");
}
if (routeDirection == HttpRouteDirection.UriGeneration)
{
return true;
}
if (!ValidateVersionHeaders(request))
{
return false;
}
ODataVersion? requestVersion = GetVersion(request);
return requestVersion.HasValue && requestVersion.Value >= MinVersion && requestVersion.Value <= MaxVersion;
}
示例11: Match
public bool Match(System.Net.Http.HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
{
if (values == null) // shouldn't ever hit this.
return true;
if (!values.ContainsKey(parameterName) || !values.ContainsKey(_id)) // make sure the parameter is there.
return true;
var action = values[parameterName].ToString().ToLower();
if (string.IsNullOrEmpty(action)) // if the param key is empty in this case "action" add the method so it doesn't hit other methods like "GetStatus"
{
values[parameterName] = request.Method.ToString();
}
else if (string.IsNullOrEmpty(values[_id].ToString()))
{
var isidstr = true;
array.ToList().ForEach(x =>
{
if (action.StartsWith(x.ToLower()))
isidstr = false;
});
if (isidstr)
{
values[_id] = values[parameterName];
values[parameterName] = request.Method.ToString();
}
}
return true;
}
示例12: Match
public override bool Match(
HttpRequestMessage request,
IHttpRoute route,
string parameterName,
IDictionary<string, object> values,
HttpRouteDirection routeDirection)
{
foreach (string key in HeaderConstraints.Keys)
{
if (!request.Headers.Contains(key)
|| string.Compare(request.Headers.GetValues(key).FirstOrDefault(), HeaderConstraints[key].ToString(), true) != 0)
{
return false;
}
}
var queries = request.GetQueryNameValuePairs().ToDictionary(p => p.Key, p => p.Value);
foreach (var key in QueryStringConstraints.Keys)
{
if (!queries.ContainsKey(key)
|| string.Compare(queries[key], QueryStringConstraints[key].ToString(), true) != 0)
{
return false;
}
}
return base.Match(request, route, parameterName, values, routeDirection);
}
示例13: Match
/// <inheritdoc />
public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
{
if (parameterName == null)
{
throw Error.ArgumentNull("parameterName");
}
if (values == null)
{
throw Error.ArgumentNull("values");
}
object value;
if (values.TryGetValue(parameterName, out value) && value != null)
{
string valueString = Convert.ToString(value, CultureInfo.InvariantCulture);
int length = valueString.Length;
if (Length.HasValue)
{
return length == Length.Value;
}
else
{
return length >= MinLength.Value && length <= MaxLength.Value;
}
}
return false;
}
示例14: Match
public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values, HttpRouteDirection routeDirection)
{
object rawValue;
if (!values.TryGetValue(parameterName, out rawValue)
|| rawValue == null) {
return true;
}
if (this.ParameterType.IsInstanceOfType(rawValue)) {
return true;
}
string attemptedValue = Convert.ToString(rawValue, CultureInfo.InvariantCulture);
if (attemptedValue.Length == 0) {
return true;
}
object parsedVal;
if (!TryParse(request, parameterName, rawValue, attemptedValue, CultureInfo.InvariantCulture, out parsedVal)) {
return false;
}
if (routeDirection == HttpRouteDirection.UriResolution) {
values[parameterName] = parsedVal;
}
return true;
}
示例15: Match
public bool Match(HttpRequestMessage request, IHttpRoute route, string parameterName, IDictionary<string, object> values,
HttpRouteDirection routeDirection)
{
return request.Headers.UserAgent
.Where(ua => ua.Product != null)
.Where(ua => ua.Product.Name != null)
.Any(ua => ua.Product.Name.IndexOf("NuGet", StringComparison.InvariantCultureIgnoreCase) != -1);
}