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


C# IResponse.ThrowIfNull方法代码示例

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


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

示例1: 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

示例2: HandleResponseAsync

		public async Task<ResponseHandlerResult> HandleResponseAsync(HttpContextBase context, IResponse suggestedResponse, ICache cache, string cacheKey)
		{
			context.ThrowIfNull("context");
			suggestedResponse.ThrowIfNull("suggestedResponse");

			await new CacheResponse(suggestedResponse).WriteResponseAsync(context.Response);

			return ResponseHandlerResult.ResponseWritten();
		}
开发者ID:nathan-alden,项目名称:junior-route,代码行数:9,代码来源:NonCacheableResponseHandler.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");

            var cacheResponse = new CacheResponse(suggestedResponse);

            cacheResponse.WriteResponse(httpResponse);

            return ResponseHandlerResult.ResponseWritten();
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:12,代码来源:NonCacheableResponseHandler.cs

示例4: CacheResponse

        public CacheResponse(IResponse response)
        {
            response.ThrowIfNull("response");

            _statusCode = response.StatusCode;
            _contentType = response.ContentType;
            _charset = response.Charset ?? DefaultCharset;
            _contentEncoding = response.ContentEncoding ?? _defaultContentEncoding;
            _headers = response.Headers.Select(arg => arg.Clone()).ToArray();
            _headerEncoding = response.HeaderEncoding ?? _defaultHeaderEncoding;
            _cookies = response.Cookies.Select(arg => arg.Clone()).ToArray();
            _cachePolicy = response.CachePolicy.Clone();
            _content = response.GetContent();
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:14,代码来源:CacheResponse.cs

示例5: CacheResponse

		public CacheResponse(IResponse response)
		{
			response.ThrowIfNull("response");

			_statusCode = response.StatusCode;
			_contentType = response.ContentType;
			_charset = response.Charset ?? DefaultCharset;
			_contentEncoding = response.ContentEncoding ?? _defaultContentEncoding;
			_headers = response.Headers.Select(arg => arg.Clone()).ToArray();
			_headerEncoding = response.HeaderEncoding ?? _defaultHeaderEncoding;
			_cookies = response.Cookies.Select(arg => arg.Clone()).ToArray();
			_cachePolicy = response.CachePolicy.Clone();
			_skipIisCustomErrors = response.SkipIisCustomErrors;
			_content = new AsyncLazy<byte[]>(() => response.GetContentAsync());
		}
开发者ID:nathan-alden,项目名称:junior-route,代码行数:15,代码来源:CacheResponse.cs

示例6: 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/html")))
            {
                return ResponseHandlerResult.ResponseNotHandled();
            }

            const string format = @"<!DOCTYPE html>
            <html>
            <head>
            <title>{0}</title>
            <style>h1 {{ margin: 0; padding: 0; }}</style>
            </head>
            <body>
            <h1>{0}</h1>
            <hr/>
            HTTP {1}{2}
            </body>
            </html>";
            Response response = new Response(statusCode)
                .TextHtml()
                .Content(String.Format(format, statusCode.StatusDescription, statusCode.StatusCode, statusCode.SubStatusCode == 0 ? "" : "." + statusCode.SubStatusCode));

            response.CachePolicy.NoClientCaching();

            new CacheResponse(response).WriteResponse(httpResponse);

            httpResponse.TrySkipIisCustomErrors = true;

            return ResponseHandlerResult.ResponseWritten();
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:44,代码来源:DescriptiveHtmlStatusCodeHandler.cs

示例7: ApplyRequestFilters

        /// <summary>
        /// Applies the request filters. Returns whether or not the request has been handled 
        /// and no more processing should be done.
        /// </summary>
        /// <returns></returns>
        public virtual bool ApplyRequestFilters(IRequest req, IResponse res, object requestDto)
        {
            req.ThrowIfNull("req");
            res.ThrowIfNull("res");

            using (Profiler.Current.Step("Executing Request Filters"))
            {
                if (!req.IsMultiRequest())
                    return ApplyRequestFiltersSingle(req, res, requestDto);

                var dtos = (IEnumerable)requestDto;
                foreach (var dto in dtos)
                {
                    if (ApplyRequestFiltersSingle(req, res, dto))
                        return true;
                }
                return false;
            }
        }
开发者ID:jrmitch120,项目名称:ServiceStack,代码行数:24,代码来源:ServiceStackHost.Runtime.cs

示例8: ApplyRequestFilters

        /// <summary>
        /// Applies the request filters. Returns whether or not the request has been handled 
        /// and no more processing should be done.
        /// </summary>
        /// <returns></returns>
        public virtual bool ApplyRequestFilters(IRequest req, IResponse res, object requestDto)
        {
            req.ThrowIfNull("req");
            res.ThrowIfNull("res");

            using (Profiler.Current.Step("Executing Request Filters"))
            {
                //Exec all RequestFilter attributes with Priority < 0
                var attributes = FilterAttributeCache.GetRequestFilterAttributes(requestDto.GetType());
                var i = 0;
                for (; i < attributes.Length && attributes[i].Priority < 0; i++)
                {
                    var attribute = attributes[i];
                    Container.AutoWire(attribute);
                    attribute.RequestFilter(req, res, requestDto);
                    Release(attribute);
                    if (res.IsClosed) return res.IsClosed;
                }

                ExecTypedFilters(GlobalTypedRequestFilters, req, res, requestDto);
                if (res.IsClosed) return res.IsClosed;

                //Exec global filters
                foreach (var requestFilter in GlobalRequestFilters)
                {
                    requestFilter(req, res, requestDto);
                    if (res.IsClosed) return res.IsClosed;
                }

                //Exec remaining RequestFilter attributes with Priority >= 0
                for (; i < attributes.Length; i++)
                {
                    var attribute = attributes[i];
                    Container.AutoWire(attribute);
                    attribute.RequestFilter(req, res, requestDto);
                    Release(attribute);
                    if (res.IsClosed) return res.IsClosed;
                }

                return res.IsClosed;
            }
        }
开发者ID:JackFong,项目名称:ServiceStack,代码行数:47,代码来源:ServiceStackHost.Runtime.cs

示例9: HandleResponseAsync

		public async Task<ResponseHandlerResult> HandleResponseAsync(HttpContextBase context, IResponse suggestedResponse, ICache cache, string cacheKey)
		{
			context.ThrowIfNull("context");
			suggestedResponse.ThrowIfNull("suggestedResponse");

			StatusAndSubStatusCode statusCode = suggestedResponse.StatusCode;

			if (!_statusCodes.Contains(statusCode))
			{
				return ResponseHandlerResult.ResponseNotHandled();
			}

			AcceptHeader[] acceptHeaders = AcceptHeader.ParseMany(context.Request.Headers["Accept"]).ToArray();

			if (acceptHeaders.Any() && !acceptHeaders.Any(arg => arg.MediaTypeMatches("text/plain")))
			{
				return ResponseHandlerResult.ResponseNotHandled();
			}

			string content = String.Format(
				"HTTP {0}{1} {2}",
				statusCode.StatusCode,
				statusCode.SubStatusCode == 0 ? "" : "." + statusCode.SubStatusCode.ToString(CultureInfo.InvariantCulture),
				statusCode.StatusDescription.Length > 0 ? String.Format("({0})", statusCode.StatusDescription) : "");
			Response response = new Response(statusCode)
				.TextPlain()
				.Content(content);

			response.CachePolicy.NoClientCaching();

			await new CacheResponse(response).WriteResponseAsync(context.Response);

			context.Response.TrySkipIisCustomErrors = true;

			return ResponseHandlerResult.ResponseWritten();
		}
开发者ID:nathan-alden,项目名称:junior-route,代码行数:36,代码来源:DescriptiveTextStatusCodeHandler.cs

示例10: ApplyResponseFilters

        /// <summary>
        /// Applies the response filters. Returns whether or not the request has been handled 
        /// and no more processing should be done.
        /// </summary>
        /// <returns></returns>
        public bool ApplyResponseFilters(IRequest httpReq, IResponse httpRes, object response)
        {
            httpReq.ThrowIfNull("httpReq");
            httpRes.ThrowIfNull("httpRes");

            using (Profiler.Current.Step("Executing Response Filters"))
            {
                var responseDto = response.GetResponseDto();
                var attributes = responseDto != null
                    ? FilterAttributeCache.GetResponseFilterAttributes(responseDto.GetType())
                    : null;

                //Exec all ResponseFilter attributes with Priority < 0
                var i = 0;
                if (attributes != null)
                {
                    for (; i < attributes.Length && attributes[i].Priority < 0; i++)
                    {
                        var attribute = attributes[i];
                        Container.AutoWire(attribute);
                        attribute.ResponseFilter(httpReq, httpRes, response);
                        Release(attribute);
                        if (httpRes.IsClosed) return httpRes.IsClosed;
                    }
                }

                //Exec global filters
                foreach (var responseFilter in GlobalResponseFilters)
                {
                    responseFilter(httpReq, httpRes, response);
                    if (httpRes.IsClosed) return httpRes.IsClosed;
                }

                //Exec remaining RequestFilter attributes with Priority >= 0
                if (attributes != null)
                {
                    for (; i < attributes.Length; i++)
                    {
                        var attribute = attributes[i];
                        Container.AutoWire(attribute);
                        attribute.ResponseFilter(httpReq, httpRes, response);
                        Release(attribute);
                        if (httpRes.IsClosed) return httpRes.IsClosed;
                    }
                }

                return httpRes.IsClosed;
            }
        }
开发者ID:0815sugo,项目名称:ServiceStack,代码行数:54,代码来源:ServiceStackHost.Runtime.cs

示例11: AuthenticationFailed

        public static AuthenticateResult AuthenticationFailed(IResponse failedResponse)
        {
            failedResponse.ThrowIfNull("failedResponse");

            return new AuthenticateResult(AuthenticateResultType.AuthenticationFailed, failedResponse);
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:6,代码来源:AuthenticateResult.cs

示例12: ApplyResponseFilters

        /// <summary>
        /// Applies the response filters. Returns whether or not the request has been handled 
        /// and no more processing should be done.
        /// </summary>
        /// <returns></returns>
        public virtual bool ApplyResponseFilters(IRequest req, IResponse res, object response)
        {
            req.ThrowIfNull("req");
            res.ThrowIfNull("res");

            if (res.IsClosed)
                return true;
            using (Profiler.Current.Step("Executing Response Filters"))
            {
                var batchResponse = req.IsMultiRequest() ? response as IEnumerable : null;
                if (batchResponse == null)
                    return ApplyResponseFiltersSingle(req, res, response);

                foreach (var dto in batchResponse)
                {
                    if (ApplyResponseFiltersSingle(req, res, dto))
                        return true;
                }
                return false;
            }
        }
开发者ID:yuinlin,项目名称:ServiceStack,代码行数:26,代码来源:ServiceStackHost.Runtime.cs

示例13: ResponseSuggested

        public static ResponseHandlerResult ResponseSuggested(IResponse suggestedResponse)
        {
            suggestedResponse.ThrowIfNull("suggestedResponse");

            return new ResponseHandlerResult(ResponseHandlerResultType.ResponseSuggested, suggestedResponse);
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:6,代码来源:ResponseHandlerResult.cs

示例14: ResponseGenerated

        public static ValidateResult ResponseGenerated(IResponse response)
        {
            response.ThrowIfNull("response");

            return new ValidateResult(ValidateResultType.ResponseGenerated, response);
        }
开发者ID:nathan-alden,项目名称:junior-route,代码行数:6,代码来源:ValidateResult.cs

示例15: HandleResponseAsync

		public async Task<ResponseHandlerResult> HandleResponseAsync(HttpContextBase context, IResponse suggestedResponse, ICache cache, string cacheKey)
		{
			context.ThrowIfNull("context");
			suggestedResponse.ThrowIfNull("suggestedResponse");

			if (!suggestedResponse.CachePolicy.HasPolicy || cache == null || cacheKey == null)
			{
				return ResponseHandlerResult.ResponseNotHandled();
			}

			CacheItem cacheItem = await cache.GetAsync(cacheKey);
			string responseETag = suggestedResponse.CachePolicy.ETag;

			#region If-Match precondition header

			IfMatchHeader[] ifMatchHeaders = IfMatchHeader.ParseMany(context.Request.Headers["If-Match"]).ToArray();

			// Only consider If-Match headers if response status code is 2xx or 412
			if (ifMatchHeaders.Any() && ((suggestedResponse.StatusCode.StatusCode >= 200 && suggestedResponse.StatusCode.StatusCode <= 299) || suggestedResponse.StatusCode.StatusCode == 412))
			{
				// Return 412 if no If-Match header matches the response ETag
				// Return 412 if an "If-Match: *" header is present and the response has no ETag
				if (ifMatchHeaders.All(arg => arg.EntityTag.Value != responseETag) ||
				    (responseETag == null && ifMatchHeaders.Any(arg => arg.EntityTag.Value == "*")))
				{
					return await WriteResponseAsync(context.Response, new Response().PreconditionFailed());
				}
			}

			#endregion

			#region If-None-Match precondition header

			IfNoneMatchHeader[] ifNoneMatchHeaders = IfNoneMatchHeader.ParseMany(context.Request.Headers["If-None-Match"]).ToArray();

			if (ifNoneMatchHeaders.Any())
			{
				// Return 304 if an If-None-Match header matches the response ETag and the request method was GET or HEAD
				// Return 304 if an "If-None-Match: *" header is present, the response has an ETag and the request method was GET or HEAD
				// Return 412 if an "If-None-Match: *" header is present, the response has an ETag and the request method was not GET or HEAD
				if (ifNoneMatchHeaders.Any(arg => arg.EntityTag.Value == responseETag) ||
				    (ifNoneMatchHeaders.Any(arg => arg.EntityTag.Value == "*") && responseETag != null))
				{
					if (String.Equals(context.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase) || String.Equals(context.Request.HttpMethod, "HEAD", StringComparison.OrdinalIgnoreCase))
					{
						if (cacheItem != null)
						{
							cacheItem.Response.CachePolicy.Apply(context.Response.Cache);
						}
						else
						{
							suggestedResponse.CachePolicy.Apply(context.Response.Cache);
						}

						return await WriteResponseAsync(context.Response, new Response().NotModified());
					}

					return await WriteResponseAsync(context.Response, new Response().PreconditionFailed());
				}
			}

			#endregion

			#region If-Modified-Since precondition header

			IfModifiedSinceHeader ifModifiedSinceHeader = IfModifiedSinceHeader.Parse(context.Request.Headers["If-Modified-Since"]);
			bool validIfModifiedSinceHttpDate = ifModifiedSinceHeader != null && ifModifiedSinceHeader.HttpDate <= _systemClock.UtcDateTime;

			// Only consider an If-Modified-Since header if response status code is 200 and the HTTP-date is valid
			if (suggestedResponse.StatusCode.ParsedStatusCode == HttpStatusCode.OK && validIfModifiedSinceHttpDate)
			{
				// Return 304 if the response was cached before the HTTP-date
				if (cacheItem != null && cacheItem.CachedUtcTimestamp < ifModifiedSinceHeader.HttpDate)
				{
					return await WriteResponseAsync(context.Response, new Response().NotModified());
				}
			}

			#endregion

			#region If-Unmodified-Since precondition header

			IfUnmodifiedSinceHeader ifUnmodifiedSinceHeader = IfUnmodifiedSinceHeader.Parse(context.Request.Headers["If-Unmodified-Since"]);
			bool validIfUnmodifiedSinceHttpDate = ifUnmodifiedSinceHeader != null && ifUnmodifiedSinceHeader.HttpDate <= _systemClock.UtcDateTime;

			// Only consider an If-Unmodified-Since header if response status code is 2xx or 412 and the HTTP-date is valid
			if (((suggestedResponse.StatusCode.StatusCode >= 200 && suggestedResponse.StatusCode.StatusCode <= 299) || suggestedResponse.StatusCode.StatusCode == 412) && validIfUnmodifiedSinceHttpDate)
			{
				// Return 412 if the previous response was removed from the cache or was cached again at a later time
				if (cacheItem == null || cacheItem.CachedUtcTimestamp >= ifUnmodifiedSinceHeader.HttpDate)
				{
					return await WriteResponseAsync(context.Response, new Response().PreconditionFailed());
				}
			}

			#endregion

			#region No server caching

			// Do not cache the response when the response sends a non-cacheable status code, or when an Authorization header is present
//.........这里部分代码省略.........
开发者ID:kelong,项目名称:JuniorRoute,代码行数:101,代码来源:CacheableResponseHandler.cs


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