本文整理汇总了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;
}
}
}
}
示例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);
}
示例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();
}
}