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


C# IServiceContext.GetHttpContext方法代码示例

本文整理汇总了C#中IServiceContext.GetHttpContext方法的典型用法代码示例。如果您正苦于以下问题:C# IServiceContext.GetHttpContext方法的具体用法?C# IServiceContext.GetHttpContext怎么用?C# IServiceContext.GetHttpContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IServiceContext的用法示例。


在下文中一共展示了IServiceContext.GetHttpContext方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BindObject

        private static object BindObject(string name, Type objectType, IServiceContext context)
        {
            string value = context.GetHttpContext().Request.Form.Get(name);
            object changedValue;

            return SafeConvert.TryChangeType(value, objectType, out changedValue) ? changedValue : null;
        }
开发者ID:dstarosta,项目名称:GitProjects,代码行数:7,代码来源:FromBodyAttribute.cs

示例2: OnMethodExecuting

        /// <summary>
        /// Called before a service method is executed.
        /// </summary>
        /// <param name="serviceContext">The service context.</param>
        /// <param name="behaviorContext">The "method executing" behavior context.</param>
        /// <returns>A service method action.</returns>
        public override BehaviorMethodAction OnMethodExecuting(IServiceContext serviceContext, MethodExecutingContext behaviorContext)
        {
            if (serviceContext == null)
            {
                throw new ArgumentNullException("serviceContext");
            }

            if (behaviorContext == null)
            {
                throw new ArgumentNullException("behaviorContext");
            }

            if (behaviorContext.Resource == null || m_validator == null)
            {
                return BehaviorMethodAction.Execute;
            }

            IReadOnlyCollection<ValidationError> validationErrors;

            if (!m_validator.IsValid(behaviorContext.Resource, out validationErrors))
            {
                serviceContext.GetHttpContext().Items[ResourceValidator.ValidationErrorKey] = new ResourceState(validationErrors);
            }

            return BehaviorMethodAction.Execute;
        }
开发者ID:dstarosta,项目名称:GitProjects,代码行数:32,代码来源:ValidationBehavior.cs

示例3: OnMethodAuthorizing

        /// <summary>
        /// Called during the authorization process before a service method or behavior is executed.
        /// </summary>
        /// <param name="serviceContext">The service context.</param>
        /// <param name="behaviorContext">The "method authorizing" behavior context.</param>
        /// <returns>A service method action.</returns>
        public override BehaviorMethodAction OnMethodAuthorizing(IServiceContext serviceContext, MethodAuthorizingContext behaviorContext)
        {
            if (serviceContext == null)
            {
                throw new ArgumentNullException("serviceContext");
            }

            var ranges = IPAddressRange.GetConfiguredRanges(m_sectionName).ToList();

            if (ranges.Count == 0)
            {
                return BehaviorMethodAction.Stop;
            }

            bool isAllowed = false;

            foreach (var range in ranges)
            {
                if (range.IsInRange(serviceContext.GetHttpContext().Request.UserHostAddress))
                {
                    isAllowed = true;
                    break;
                }
            }

            return isAllowed ? BehaviorMethodAction.Execute : BehaviorMethodAction.Stop;
        }
开发者ID:dstarosta,项目名称:GitProjects,代码行数:33,代码来源:AclBehavior.cs

示例4: OnMethodExecuting

        /// <summary>
        /// Called before a service method is executed.
        /// </summary>
        /// <param name="serviceContext">The service context.</param>
        /// <param name="behaviorContext">The "method executing" behavior context.</param>
        /// <returns>A service method action.</returns>
        public override BehaviorMethodAction OnMethodExecuting(IServiceContext serviceContext, MethodExecutingContext behaviorContext)
        {
            if (serviceContext == null)
            {
                throw new ArgumentNullException("serviceContext");
            }

            serviceContext.GetHttpContext().Items[ServiceCallConstants.MaxQueryResults] = AllowOverride ? (MaxResults * -1) : MaxResults;

            return BehaviorMethodAction.Execute;
        }
开发者ID:dstarosta,项目名称:GitProjects,代码行数:17,代码来源:MaxQueryResultsAttribute.cs

示例5: BindArray

        private static object BindArray(string name, Type objectType, IServiceContext context)
        {
            Type elementType = objectType.GetElementType();

            string[] values = context.GetHttpContext().Request.Form.GetValues(name) ?? new string[0];
            var changedValues = Array.CreateInstance(elementType, values.Length);

            for (int i = 0; i < values.Length; i++)
            {
                object changedArrayValue;
                changedValues.SetValue(SafeConvert.TryChangeType(values[i], elementType, out changedArrayValue) ? changedArrayValue : null, i);
            }

            return changedValues;
        }
开发者ID:dstarosta,项目名称:GitProjects,代码行数:15,代码来源:FromBodyAttribute.cs

示例6: OnMethodExecuted

        /// <summary>
        /// Called after a service method is executed.
        /// </summary>
        /// <param name="serviceContext">The service context.</param>
        /// <param name="behaviorContext">The "method executed" behavior context.</param>
        public override void OnMethodExecuted(IServiceContext serviceContext, MethodExecutedContext behaviorContext)
        {
            if (serviceContext == null)
            {
                throw new ArgumentNullException("serviceContext");
            }

            HttpContextBase httpContext = serviceContext.GetHttpContext();

            if (httpContext == null)
            {
                throw new ArgumentException(Resources.Global.MissingHttpContext, "serviceContext");
            }

            httpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
            httpContext.Response.Cache.SetValidUntilExpires(false);
            httpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
            httpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            httpContext.Response.Cache.SetNoStore();
        }
开发者ID:dstarosta,项目名称:GitProjects,代码行数:25,代码来源:NoCacheAttribute.cs

示例7: FormatRequest

        /// <summary>
        /// Deserializes HTTP message body data into an object instance of the provided type.
        /// </summary>
        /// <param name="context">The service context.</param>
        /// <param name="objectType">The object type.</param>
        /// <returns>The deserialized object.</returns>
        /// <exception cref="HttpResponseException">If the object cannot be deserialized.</exception>
        public virtual object FormatRequest(IServiceContext context, Type objectType)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (objectType == null)
            {
                throw new ArgumentNullException("objectType");
            }

            TryValidateFormValues(context.GetHttpContext());

            object resource = InitializeResource(objectType);

            if (resource == null)
            {
                return null;
            }

            NameValueCollection formData = PopulateFormData(context);

            if (formData.Count == 0)
            {
                return resource;
            }

            dynamic dynamicResource = resource as DynamicResult;

            if (dynamicResource != null)
            {
                PopulateDynamicResourceData(dynamicResource, formData);
                return dynamicResource;
            }

            PopulateResourceData(resource, formData);
            return resource;
        }
开发者ID:dstarosta,项目名称:GitProjects,代码行数:46,代码来源:FormsFormatter.cs

示例8: ArgumentNullException

        void ISecureServiceBehavior.OnMethodAuthorizing(IServiceContext serviceContext, MethodAuthorizingContext behaviorContext)
        {
            if (serviceContext == null)
            {
                throw new ArgumentNullException("serviceContext");
            }

            if (OnMethodAuthorizing(serviceContext, behaviorContext) == BehaviorMethodAction.Stop)
            {
                HttpStatusCode statusCode = serviceContext.Response.GetStatusCode();

                if (statusCode != HttpStatusCode.Unauthorized && statusCode != m_statusCode)
                {
                    throw new HttpResponseException(m_statusCode, m_statusDescription);
                }

                throw new HttpResponseException(statusCode, serviceContext.Response.GetStatusDescription());
            }

            HttpCachePolicyBase cache = serviceContext.GetHttpContext().Response.Cache;
            cache.SetProxyMaxAge(new TimeSpan(0L));
            cache.AddValidationCallback(CacheValidationHandler, new CacheValidationHandlerData(serviceContext, behaviorContext));
        }
开发者ID:dstarosta,项目名称:GitProjects,代码行数:23,代码来源:SecureServiceBehavior.cs

示例9: TrySetMaxQueryResults

        private static void TrySetMaxQueryResults(IServiceContext context, NameValueCollection queryString)
        {
            object maxResultString = context.GetHttpContext().Items[ServiceCallConstants.MaxQueryResults] ??
                                     Rest.Configuration.Options.ODataSettings.MaxResults.ToString(CultureInfo.InvariantCulture);

            int maxQueryResults = Convert.ToInt32(maxResultString, CultureInfo.InvariantCulture);

            if (maxQueryResults < 0)
            {
                if (!String.IsNullOrEmpty(queryString[TopKey]))
                {
                    return;
                }

                queryString[TopKey] = (maxQueryResults * -1).ToString(CultureInfo.InvariantCulture);
            }
            else if (maxQueryResults > 0)
            {
                string topValue = queryString[TopKey];

                if (!String.IsNullOrEmpty(topValue))
                {
                    int top;

                    if (!Int32.TryParse(topValue, out top))
                    {
                        return;
                    }

                    if (top > 0 && top < maxQueryResults)
                    {
                        maxQueryResults = top;
                    }
                }

                queryString[TopKey] = maxQueryResults.ToString(CultureInfo.InvariantCulture);
            }
        }
开发者ID:dstarosta,项目名称:GitProjects,代码行数:38,代码来源:Linq2RestODataProvider.cs


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