当前位置: 首页>>代码示例>>C#>>正文


C# IHttpRoute类代码示例

本文整理汇总了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;
        }
开发者ID:Azure,项目名称:azure-webjobs-sdk-script,代码行数:26,代码来源:HttpRouteFactory.cs

示例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;
        }
开发者ID:andreychizhov,项目名称:microsoft-aspnet-samples,代码行数:26,代码来源:SegmentPrefixConstraint.cs

示例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;
 }
开发者ID:diouf,项目名称:apress-recipes-webapi,代码行数:7,代码来源:VersionConstraint.cs

示例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;
        }
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:27,代码来源:LongHttpRouteConstraint.cs

示例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;
 }
开发者ID:liumeifu,项目名称:OSky,代码行数:28,代码来源:StartsWithConstraint.cs

示例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);
                    }
                }
            }
        }
开发者ID:davidsavagejr,项目名称:SDammann.WebApi.Versioning,代码行数:33,代码来源:VersionedApiExplorer.cs

示例7: Match

 public bool Match(
     HttpRequestMessage request,
     IHttpRoute route,
     string parameterName,
     IDictionary<string, object> values,
     HttpRouteDirection routeDirection) =>
         Match(parameterName, values);
开发者ID:KimberlyPhan,项目名称:Its.Cqrs,代码行数:7,代码来源:GuidConstraint.cs

示例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);
        }
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:31,代码来源:OptionalHttpRouteConstraint.cs

示例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);
        }
开发者ID:Cefa68000,项目名称:AttributeRouting,代码行数:7,代码来源:InboundHttpMethodConstraint.cs

示例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;
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:28,代码来源:ODataVersionConstraint.cs

示例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;
        }
开发者ID:ud7070,项目名称:UDTest,代码行数:30,代码来源:StartWithConstraint.cs

示例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);
        }
开发者ID:bigred8982,项目名称:Swashbuckle.OData,代码行数:28,代码来源:ODataVersionRouteConstraint.cs

示例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;
        }
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:29,代码来源:LengthHttpRouteConstraint.cs

示例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;
        }
开发者ID:brettveenstra,项目名称:MvcCodeRouting,代码行数:32,代码来源:TypeAwareRouteConstraint.cs

示例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);
 }
开发者ID:Pliner,项目名称:TinyFeed,代码行数:8,代码来源:NuGetUserAgentConstraint.cs


注:本文中的IHttpRoute类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。