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


C# HttpError.ContainsKey方法代码示例

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


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

示例1: ExceptionConstructorWithoutDetail_AddsCorrectDictionaryItems

        public void ExceptionConstructorWithoutDetail_AddsCorrectDictionaryItems()
        {
            HttpError error = new HttpError(new ArgumentException("error", new Exception()), false);

            Assert.Contains(new KeyValuePair<string, object>("Message", "An error has occurred."), error);
            Assert.False(error.ContainsKey("ExceptionMessage"));
            Assert.False(error.ContainsKey("ExceptionType"));
            Assert.False(error.ContainsKey("StackTrace"));
            Assert.False(error.ContainsKey("InnerException"));
        }
开发者ID:mikevpeters,项目名称:aspnetwebstack,代码行数:10,代码来源:HttpErrorTest.cs

示例2: OnActionExecuting

        /// <summary>
        /// Occurs before the action method is invoked.
        /// </summary>
        /// <param name="actionContext">The action context.</param>
        public override void OnActionExecuting( HttpActionContext actionContext )
        {
            ModelStateDictionary modelState = actionContext.ModelState;

            IEntity valueArg = null;
            if ( actionContext.ActionArguments.ContainsKey( "value" ) )
            {
                valueArg = actionContext.ActionArguments["value"] as IEntity;
            }

            if ( valueArg != null )
            {
                Type entityType = actionContext.ActionArguments["value"].GetType();
                IgnoreModelErrorsAttribute ignoreModelErrorsAttribute = entityType.GetCustomAttributes( typeof( IgnoreModelErrorsAttribute ), true ).FirstOrDefault() as IgnoreModelErrorsAttribute;

                if ( ignoreModelErrorsAttribute != null )
                {
                    foreach ( string key in ignoreModelErrorsAttribute.Keys )
                    {
                        IEnumerable<string> matchingKeys = modelState.Keys.Where( x => Regex.IsMatch( x, key ) );
                        foreach ( string matchingKey in matchingKeys )
                        {
                            modelState[matchingKey].Errors.Clear();
                        }
                    }
                }
            }

            if ( !actionContext.ModelState.IsValid )
            {
                HttpError httpError = new HttpError();

                foreach ( var item in actionContext.ModelState )
                {
                    foreach ( ModelError error in item.Value.Errors )
                    {
                        if ( !httpError.ContainsKey( item.Key ) )
                        {
                            httpError.Add( item.Key, string.Empty );
                            httpError[item.Key] += error.ErrorMessage;
                        }
                        else
                        {
                            httpError[item.Key] += Environment.NewLine + error.ErrorMessage;
                        }
                    }
                }

                actionContext.Response = actionContext.Request.CreateErrorResponse( HttpStatusCode.BadRequest, httpError );
            }
        }
开发者ID:Ganon11,项目名称:Rock,代码行数:55,代码来源:ValidateAttribute.cs

示例3: HttpErrors_UseCaseInsensitiveComparer

        public void HttpErrors_UseCaseInsensitiveComparer(HttpError httpError)
        {
            var lowercaseKey = "abcd";
            var uppercaseKey = "ABCD";

            httpError[lowercaseKey] = "error";

            Assert.True(httpError.ContainsKey(lowercaseKey));
            Assert.True(httpError.ContainsKey(uppercaseKey));
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:10,代码来源:HttpErrorTest.cs

示例4: Execute

        private HttpResponseMessage Execute()
        {
            var httpResponseMessage = new HttpResponseMessage();

            try
            {
                var negotiationResult = ContentNegotiator.Negotiate(typeof(HttpError), Request, Formatters);

                if (negotiationResult == null)
                {
                    httpResponseMessage.StatusCode = HttpStatusCode.NotAcceptable;
                }
                else
                {
                    var error = new HttpError("Validation Failed");
                    foreach (var err in _exception.ValidationErrors)
                    {
                        if (!error.ContainsKey(err.ItemName))
                        {
                            error.Add(err.ItemName, new Collection<ApiError>());
                        }

                        ((ICollection<ApiError>)error[err.ItemName]).Add(new ApiError
                        {
                            ErrorCode = err.ErrorCode,
                            Message = err.ErrorMessage
                        });
                    }

                    httpResponseMessage.StatusCode = HttpStatusCode.BadRequest;
                    httpResponseMessage.Content = new ObjectContent<HttpError>(error, negotiationResult.Formatter, negotiationResult.MediaType);
                }

                httpResponseMessage.RequestMessage = Request;
            }
            catch
            {
                httpResponseMessage.Dispose();
                throw;
            }

            return httpResponseMessage;
        }
开发者ID:magonzalez,项目名称:WebApi-OAuth2-StarterKit,代码行数:43,代码来源:ValidationExceptionResult.cs


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