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


C# HttpContext.ThrowIfNull方法代码示例

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


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

示例1: ProcessRequestAsync

		public override async Task ProcessRequestAsync(HttpContext context)
		{
			context.ThrowIfNull("context");

			var request = new HttpRequestWrapper(context.Request);
			var response = new HttpResponseWrapper(context.Response);

			if (_antiCsrfCookieManager != null && _antiCsrfNonceValidator != null && _antiCsrfResponseGenerator != null)
			{
				if (!String.IsNullOrEmpty(context.Request.ContentType))
				{
					try
					{
						var contentType = new ContentType(context.Request.ContentType);

						if (String.Equals(contentType.MediaType, "application/x-www-form-urlencoded", StringComparison.OrdinalIgnoreCase) || String.Equals(contentType.MediaType, "multipart/form-data", StringComparison.OrdinalIgnoreCase))
						{
							ValidationResult validationResult = await _antiCsrfNonceValidator.ValidateAsync(request);
							ResponseResult responseResult = await _antiCsrfResponseGenerator.GetResponseAsync(validationResult);

							if (responseResult.ResultType == ResponseResultType.ResponseGenerated)
							{
								await ProcessResponseAsync(context, responseResult.Response, null);
								return;
							}
						}
					}
					catch (FormatException)
					{
					}
				}

				await _antiCsrfCookieManager.ConfigureCookieAsync(request, response);
			}
			{
				IEnumerable<RouteMatchResult> routeMatchResults = await GetRouteMatchResultsAsync(request);
				IEnumerable<Task<ResponseGenerators.ResponseResult>> responseResultTasks = _responseGenerators.Select(arg => arg.GetResponseAsync(new HttpContextWrapper(context), routeMatchResults));

				foreach (Task<ResponseGenerators.ResponseResult> responseResultTask in responseResultTasks)
				{
					ResponseGenerators.ResponseResult responseResult = await responseResultTask;

					if (responseResult.ResultType == ResponseGenerators.ResponseResultType.ResponseGenerated)
					{
						await ProcessResponseAsync(context, await responseResult.Response, responseResult.CacheKey);
						return;
					}
				}
			}
		}
开发者ID:kelong,项目名称:JuniorRoute,代码行数:50,代码来源:AspNetHttpHandler.cs

示例2: ProcessRequest

        public void ProcessRequest(HttpContext context)
        {
            context.ThrowIfNull("context");

            var request = new HttpRequestWrapper(context.Request);
            var response = new HttpResponseWrapper(context.Response);
            // ReSharper disable ImplicitlyCapturedClosure
            RouteMatchResult[] routeMatchResults = _routes.Select(arg => new RouteMatchResult(arg, arg.MatchesRequest(request))).ToArray();
            // ReSharper restore ImplicitlyCapturedClosure
            ResponseResult responseResult = _responseGenerators
                .Select(arg => arg.GetResponse(request, routeMatchResults))
                .FirstOrDefault(arg => arg.ResultType != ResponseResultType.ResponseNotGenerated);

            if (responseResult == null)
            {
                throw new ApplicationException("No response was generated.");
            }

            ProcessResponse(request, response, responseResult.Response, responseResult.CacheKey);
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:20,代码来源:AspNetHttpHandler.cs

示例3: ProcessRequestAsync

		public override async Task ProcessRequestAsync(HttpContext context)
		{
			context.ThrowIfNull("context");

			var contextWrapper = new HttpContextWrapper(context);
			var requestWrapper = new HttpRequestWrapper(context.Request);
			var responseWrapper = new HttpResponseWrapper(context.Response);
			ExceptionDispatchInfo exceptionDispatchInfo = null;

			try
			{
				foreach (IRequestValidator requestValidator in _requestValidators)
				{
					ValidateResult validateResult = await requestValidator.Validate(requestWrapper, responseWrapper);

					if (validateResult.ResultType == ValidateResultType.RequestValidated)
					{
						continue;
					}

					await ProcessResponseAsync(context, validateResult.Response, null);
					return;
				}

				IEnumerable<RouteMatchResult> routeMatchResults = _routes.Select(arg => new RouteMatchResult(arg, arg.MatchesRequest(requestWrapper)));
				IEnumerable<Task<ResponseResult>> responseResultTasks = _responseGenerators.Select(arg => arg.GetResponseAsync(contextWrapper, routeMatchResults));

				foreach (Task<ResponseResult> responseResultTask in responseResultTasks)
				{
					ResponseResult responseResult = await responseResultTask;

					if (responseResult.ResultType != ResponseResultType.ResponseGenerated)
					{
						continue;
					}

					await ProcessResponseAsync(context, await responseResult.Response, responseResult.CacheKey);
					return;
				}
			}
			catch (Exception exception)
			{
				exceptionDispatchInfo = ExceptionDispatchInfo.Capture(exception);
			}

			if (exceptionDispatchInfo != null)
			{
				foreach (IErrorHandler errorHandler in _errorHandlers)
				{
					if ((await errorHandler.HandleAsync(contextWrapper, exceptionDispatchInfo.SourceException)).ResultType != HandleResultType.Handled)
					{
						continue;
					}

					exceptionDispatchInfo = null;
					break;
				}
			}
			if (exceptionDispatchInfo != null)
			{
				exceptionDispatchInfo.Throw();
			}
		}
开发者ID:nathan-alden,项目名称:junior-route,代码行数:63,代码来源:AspNetHttpHandler.cs


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