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


C# HttpRequestBase.ThrowIfNull方法代码示例

本文整理汇总了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();
		}
开发者ID:nathan-alden,项目名称:junior-route,代码行数:31,代码来源:AntiCsrfRequestValidator.cs

示例2: CanMapType

        public bool CanMapType(HttpRequestBase request, Type parameterType)
        {
            request.ThrowIfNull("request");
            parameterType.ThrowIfNull("parameterType");

            return request.ContentType == "application/json" && _parameterTypeMatchDelegate(parameterType);
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:7,代码来源:JsonModelMapper.cs

示例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();
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:32,代码来源:DescriptiveTextStatusCodeHandler.cs

示例4: GetResponse

        public ResponseResult GetResponse(HttpRequestBase request, IEnumerable<RouteMatchResult> routeMatchResults)
        {
            request.ThrowIfNull("request");
            routeMatchResults.ThrowIfNull("routeMatchResults");

            return ResponseResult.ResponseGenerated(Response.NotFound());
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:7,代码来源:NotFoundGenerator.cs

示例5: CanMapType

        public bool CanMapType(HttpRequestBase request, Type parameterType)
        {
            request.ThrowIfNull("request");
            parameterType.ThrowIfNull("parameterType");

            return parameterType.ImplementsInterface<IConvertible>();
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:7,代码来源:QueryStringToIConvertibleMapper.cs

示例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;
		}
开发者ID:kelong,项目名称:JuniorRoute,代码行数:35,代码来源:FormsAuthenticationHelper.cs

示例7: CanMapType

        public bool CanMapType(HttpRequestBase request, Type parameterType)
        {
            request.ThrowIfNull("request");
            parameterType.ThrowIfNull("parameterType");

            return true;
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:7,代码来源:DefaultValueMapper.cs

示例8: CanMapType

        public bool CanMapType(HttpRequestBase request, Type parameterType)
        {
            request.ThrowIfNull("request");
            parameterType.ThrowIfNull("parameterType");

            return _parameterTypeMatchDelegate(parameterType);
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:7,代码来源:ModelMapper.cs

示例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);
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:27,代码来源:JsonModelMapper.cs

示例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());
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:8,代码来源:DefaultValueMapper.cs

示例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();
		}
开发者ID:kelong,项目名称:JuniorRoute,代码行数:8,代码来源:DefaultValueMapper.cs

示例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());
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:9,代码来源:DefaultValueMapper.cs

示例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;
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:54,代码来源:ParameterValueRetriever.cs

示例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));
        }
开发者ID:nathan-alden,项目名称:junior-route,代码行数:11,代码来源:OrRestriction.cs

示例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();
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:12,代码来源:NonCacheableResponseHandler.cs


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