本文整理汇总了C#中System.Web.HttpRequestBase.ThrowIfNull方法的典型用法代码示例。如果您正苦于以下问题:C# HttpRequestBase.ThrowIfNull方法的具体用法?C# HttpRequestBase.ThrowIfNull怎么用?C# HttpRequestBase.ThrowIfNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpRequestBase
的用法示例。
在下文中一共展示了HttpRequestBase.ThrowIfNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Validate
public async Task<ValidateResult> Validate(HttpRequestBase request, HttpResponseBase response)
{
request.ThrowIfNull("request");
response.ThrowIfNull("response");
if (!String.IsNullOrEmpty(request.ContentType))
{
try
{
var contentType = new ContentType(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)
{
return ValidateResult.ResponseGenerated(responseResult.Response);
}
}
}
catch (FormatException)
{
}
}
await _antiCsrfCookieManager.ConfigureCookieAsync(request, response);
return ValidateResult.RequestValidated();
}
示例2: CanMapType
public bool CanMapType(HttpRequestBase request, Type parameterType)
{
request.ThrowIfNull("request");
parameterType.ThrowIfNull("parameterType");
return request.ContentType == "application/json" && _parameterTypeMatchDelegate(parameterType);
}
示例3: HandleResponse
public ResponseHandlerResult HandleResponse(HttpRequestBase httpRequest, HttpResponseBase httpResponse, IResponse suggestedResponse, ICache cache, string cacheKey)
{
httpRequest.ThrowIfNull("httpRequest");
httpResponse.ThrowIfNull("httpResponse");
suggestedResponse.ThrowIfNull("suggestedResponse");
StatusAndSubStatusCode statusCode = suggestedResponse.StatusCode;
if (!_statusCodes.Contains(statusCode))
{
return ResponseHandlerResult.ResponseNotHandled();
}
AcceptHeader[] acceptHeaders = AcceptHeader.ParseMany(httpRequest.Headers["Accept"]).ToArray();
if (acceptHeaders.Any() && !acceptHeaders.Any(arg => arg.MediaTypeMatches("text/plain")))
{
return ResponseHandlerResult.ResponseNotHandled();
}
Response response = new Response(statusCode)
.TextPlain()
.Content(String.Format("{0} {1}", statusCode.StatusDescription, statusCode.StatusDescription.Length > 0 ? String.Format("({0})", statusCode.StatusDescription) : ""));
response.CachePolicy.NoClientCaching();
new CacheResponse(response).WriteResponse(httpResponse);
httpResponse.TrySkipIisCustomErrors = true;
return ResponseHandlerResult.ResponseWritten();
}
示例4: GetResponse
public ResponseResult GetResponse(HttpRequestBase request, IEnumerable<RouteMatchResult> routeMatchResults)
{
request.ThrowIfNull("request");
routeMatchResults.ThrowIfNull("routeMatchResults");
return ResponseResult.ResponseGenerated(Response.NotFound());
}
示例5: CanMapType
public bool CanMapType(HttpRequestBase request, Type parameterType)
{
request.ThrowIfNull("request");
parameterType.ThrowIfNull("parameterType");
return parameterType.ImplementsInterface<IConvertible>();
}
示例6: RenewTicket
public Cookie RenewTicket(HttpRequestBase request)
{
request.ThrowIfNull("request");
HttpCookie cookie = GetRequestCookie(request);
if (cookie == null)
{
return null;
}
FormsAuthenticationTicket ticket;
try
{
ticket = System.Web.Security.FormsAuthentication.Decrypt(cookie.Value);
}
catch (ArgumentException)
{
return null;
}
if (ticket == null || ticket.Expired)
{
return null;
}
if (!_configuration.SlidingExpiration)
{
return new Cookie(cookie);
}
ticket = System.Web.Security.FormsAuthentication.RenewTicketIfOld(ticket);
return ticket != null ? GenerateTicket(ticket.Expiration, ticket.UserData) : null;
}
示例7: CanMapType
public bool CanMapType(HttpRequestBase request, Type parameterType)
{
request.ThrowIfNull("request");
parameterType.ThrowIfNull("parameterType");
return true;
}
示例8: CanMapType
public bool CanMapType(HttpRequestBase request, Type parameterType)
{
request.ThrowIfNull("request");
parameterType.ThrowIfNull("parameterType");
return _parameterTypeMatchDelegate(parameterType);
}
示例9: Map
public MapResult Map(HttpRequestBase request, Type type, MethodInfo method, ParameterInfo parameter)
{
request.ThrowIfNull("request");
type.ThrowIfNull("type");
method.ThrowIfNull("method");
parameter.ThrowIfNull("parameter");
Type parameterType = parameter.ParameterType;
var reader = new StreamReader(request.InputStream, request.ContentEncoding);
string json = reader.ReadToEnd();
object jsonModel;
try
{
jsonModel = JsonConvert.DeserializeObject(json, parameterType, _serializerSettings);
}
catch (Exception exception)
{
if (_errorHandling == DataConversionErrorHandling.ThrowException)
{
throw new ApplicationException(String.Format("Request content could not be deserialized to '{0}'.", parameterType.FullName), exception);
}
jsonModel = parameterType.GetDefaultValue();
}
return MapResult.ValueMapped(jsonModel);
}
示例10: Map
public MapResult Map(HttpRequestBase request, Type modelType, PropertyInfo property)
{
request.ThrowIfNull("request");
modelType.ThrowIfNull("modelType");
property.ThrowIfNull("property");
return MapResult.ValueMapped(property.PropertyType.GetDefaultValue());
}
示例11: MapAsync
public Task<MapResult> MapAsync(HttpRequestBase request, Type modelType, PropertyInfo property)
{
request.ThrowIfNull("request");
modelType.ThrowIfNull("modelType");
property.ThrowIfNull("property");
return MapResult.ValueMapped(property.PropertyType.GetDefaultValue()).AsCompletedTask();
}
示例12: Map
public MapResult Map(HttpRequestBase request, Type type, MethodInfo method, ParameterInfo parameter)
{
request.ThrowIfNull("request");
type.ThrowIfNull("type");
method.ThrowIfNull("method");
parameter.ThrowIfNull("parameter");
return MapResult.ValueMapped(parameter.ParameterType.GetDefaultValue());
}
示例13: GetParameterValues
public IEnumerable<object> GetParameterValues(HttpRequestBase request, Type type, MethodInfo method)
{
request.ThrowIfNull("request");
type.ThrowIfNull("type");
method.ThrowIfNull("method");
ParameterInfo[] parameterInfos = method.GetParameters();
var parameterValues = new List<object>();
foreach (ParameterInfo parameterInfo in parameterInfos)
{
Type parameterType = parameterInfo.ParameterType;
string parameterName = parameterInfo.Name;
Type currentParameterType = parameterType;
do
{
bool mapped = false;
foreach (IParameterMapper parameterMapper in _parameterMappers.Where(arg => arg.CanMapType(request, parameterType)))
{
MapResult mapResult = parameterMapper.Map(request, type, method, parameterInfo);
if (mapResult.ResultType == MapResultType.ValueNotMapped)
{
continue;
}
parameterValues.Add(mapResult.Value);
mapped = true;
break;
}
if (mapped)
{
break;
}
currentParameterType = currentParameterType.BaseType;
} while (currentParameterType != null);
if (currentParameterType == null)
{
throw new ApplicationException(
String.Format(
"No request parameter mapper was found for parameter '{0} {1}' of '{2}.{3}'.",
parameterType.FullName,
parameterName,
type.FullName,
method.Name));
}
}
return parameterValues;
}
示例14: MatchesRequest
public MatchResult MatchesRequest(HttpRequestBase request)
{
request.ThrowIfNull("request");
MatchResult[] matchResults = _restrictions.Select(arg => arg.MatchesRequest(request)).ToArray();
MatchResult matchingMatchResult = matchResults.FirstOrDefault(arg => arg.ResultType == MatchResultType.RestrictionMatched);
return matchingMatchResult != null
? MatchResult.RestrictionMatched(matchingMatchResult.MatchedRestrictions)
: MatchResult.RestrictionNotMatched(Enumerable.Empty<IRestriction>(), matchResults.SelectMany(arg => arg.UnmatchedRestrictions));
}
示例15: HandleResponse
public ResponseHandlerResult HandleResponse(HttpRequestBase httpRequest, HttpResponseBase httpResponse, IResponse suggestedResponse, ICache cache, string cacheKey)
{
httpRequest.ThrowIfNull("httpRequest");
httpResponse.ThrowIfNull("httpResponse");
suggestedResponse.ThrowIfNull("suggestedResponse");
var cacheResponse = new CacheResponse(suggestedResponse);
cacheResponse.WriteResponse(httpResponse);
return ResponseHandlerResult.ResponseWritten();
}