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


C# IHttpResponse.WriteErrorToResponse方法代码示例

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


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

示例1: ProcessRequest

        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            var isDebugRequest = httpReq.RawUrl.ToLower().Contains("debug");
            if (!isDebugRequest)
            {
                base.ProcessRequest(httpReq, httpRes, operationName);
                return;
            }

            try
            {
                var request = CreateRequest(httpReq, operationName);

                var response = ExecuteService(request,
                    HandlerAttributes | GetEndpointAttributes(httpReq), httpReq);

                WriteDebugResponse(httpRes, response);
            }
            catch (Exception ex)
            {
                var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);

                httpRes.WriteErrorToResponse(EndpointAttributes.Jsv, operationName, errorMessage, ex);
            }
        }
开发者ID:nigthwatch,项目名称:ServiceStack,代码行数:25,代码来源:JsvSyncReplyHandler.cs

示例2: ProcessRequest

        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            var isDebugRequest = httpReq.RawUrl.ToLower().Contains("debug");
            if (!isDebugRequest)
            {
                base.ProcessRequest(httpReq, httpRes, operationName);
                return;
            }

            try
            {
                var request = CreateRequest(httpReq, operationName);

                var response = ExecuteService(request,
                    HandlerAttributes | GetEndpointAttributes(httpReq), httpReq);

                WriteDebugResponse(httpRes, response);
            }
            catch (Exception ex)
            {
                bool writeErrorToResponse = ServiceStack.Configuration.ConfigUtils.GetAppSetting<bool>(ServiceStack.Configuration.Keys.WriteErrorsToResponse, true);
                if(!writeErrorToResponse) {
                    throw;
                }
                try {
                    if(!httpRes.IsClosed) {
                        var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);
                        httpRes.WriteErrorToResponse(EndpointAttributes.Jsv, operationName, errorMessage, ex);
                    }
                }
                catch(Exception /*WriteErrorEx*/) {
                    //Exception in writing to response should not hide the original exception
                    //Log.Info("Failed to write error to response: {0}", WriteErrorEx);
                    //rethrow the original exception
                    throw ex;
                }
            }
        }
开发者ID:letssellsomebananas,项目名称:ServiceStack,代码行数:38,代码来源:JsvSyncReplyHandler.cs

示例3: HandleException

        protected void HandleException(string responseContentType, IHttpResponse httpRes, string operationName, Exception ex)
        {
            var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);
            Log.Error(errorMessage, ex);

            try
            {
                var statusCode = ex is SerializationException ? HttpStatusCode.BadRequest : HttpStatusCode.InternalServerError;
                //httpRes.WriteToResponse always calls .Close in it's finally statement so
                //if there is a problem writing to response, by now it will be closed
                if (!httpRes.IsClosed)
                {
                    httpRes.WriteErrorToResponse(responseContentType, operationName, errorMessage, ex, statusCode);
                }
            }
            catch (Exception writeErrorEx)
            {
                //Exception in writing to response should not hide the original exception
                Log.Info("Failed to write error to response: {0}", writeErrorEx);
                //rethrow the original exception
                throw ex;
            }
        }
开发者ID:half-evil,项目名称:ServiceStack,代码行数:23,代码来源:EndpointHandlerBase.cs

示例4: ProcessRequest

        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            try
            {
                var contentType = httpReq.GetQueryStringContentType() ?? this.HandlerContentType;
                var callback = httpReq.QueryString["callback"];
                var doJsonp = EndpointHost.Config.AllowJsonpRequests
                              && !string.IsNullOrEmpty(callback);

                var request = CreateRequest(httpReq, operationName);

                var response = GetResponse(httpReq, request);

                var serializer = GetStreamSerializer(contentType);

                if (doJsonp) httpRes.Write(callback + "(");

                httpRes.WriteToResponse(response, serializer, contentType);

                if (doJsonp) httpRes.Write(")");

            }
            catch (Exception ex)
            {
                var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);
                Log.Error(errorMessage, ex);

                httpRes.WriteErrorToResponse(HandlerContentType, operationName, errorMessage, ex);
            }
        }
开发者ID:firstsee,项目名称:ServiceStack,代码行数:30,代码来源:GenericHandler.cs

示例5: ProcessRequest

        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            var responseContentType = EndpointHost.Config.DefaultContentType;
            try
            {
                var restPath = GetRestPath(httpReq.HttpMethod, httpReq.PathInfo);
                if (restPath == null)
                    throw new NotSupportedException("No RestPath found for: " + httpReq.HttpMethod + " " + httpReq.PathInfo);

                operationName = restPath.RequestType.Name;

                var callback = httpReq.QueryString["callback"];
                var doJsonp = EndpointHost.Config.AllowJsonpRequests
                              && !string.IsNullOrEmpty(callback);

                responseContentType = httpReq.ResponseContentType;
                EndpointHost.Config.AssertContentType(responseContentType);

                var request = GetRequest(httpReq, restPath);
                if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request)) return;

                var response = GetResponse(httpReq, request);
                if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, response)) return;

                if (responseContentType.Contains("jsv") && !string.IsNullOrEmpty(httpReq.QueryString["debug"]))
                {
                    JsvSyncReplyHandler.WriteDebugResponse(httpRes, response);
                    return;
                }

                if (doJsonp)
                    httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
                else
                    httpRes.WriteToResponse(httpReq, response);
            }
            catch (Exception ex)
            {
                var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);
                Log.Error(errorMessage, ex);

                var attrEndpointType = ContentType.GetEndpointAttributes(responseContentType);
                httpRes.WriteErrorToResponse(attrEndpointType, operationName, errorMessage, ex);
            }
        }
开发者ID:nuxleus,项目名称:ServiceStack,代码行数:44,代码来源:RestHandler.cs

示例6: ProcessRequest

        //public StreamSerializerDelegate GetStreamSerializer(string contentType)
        //{
        //    return GetContentFilters().GetStreamSerializer(contentType);
        //}
        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            try
            {
                EndpointHost.Config.AssertFeatures(usesFeature);

                httpReq.ResponseContentType = httpReq.GetQueryStringContentType() ?? this.HandlerContentType;
                var callback = httpReq.QueryString["callback"];
                var doJsonp = EndpointHost.Config.AllowJsonpRequests
                              && !string.IsNullOrEmpty(callback);

                var request = CreateRequest(httpReq, operationName);
                if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request)) return;

                var response = GetResponse(httpReq, request);
                if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, response)) return;

                if (doJsonp)
                    httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
                else
                    httpRes.WriteToResponse(httpReq, response);
            }
            catch (Exception ex)
            {
                var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);
                Log.Error(errorMessage, ex);

                httpRes.WriteErrorToResponse(HandlerContentType, operationName, errorMessage, ex);
            }
        }
开发者ID:nuxleus,项目名称:ServiceStack,代码行数:34,代码来源:GenericHandler.cs

示例7: ProcessRequest

        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            var responseContentType = EndpointHost.Config.DefaultContentType;
            try
            {
                var restPath = GetRestPath(httpReq.HttpMethod, httpReq.PathInfo);
                if (restPath == null)
                    throw new NotSupportedException("No RestPath found for: " + httpReq.HttpMethod + " " + httpReq.PathInfo);

                operationName = restPath.RequestType.Name;

                var callback = httpReq.QueryString["callback"];
                var doJsonp = EndpointHost.Config.AllowJsonpRequests
                              && !string.IsNullOrEmpty(callback);

                responseContentType = httpReq.ResponseContentType;
                EndpointHost.Config.AssertContentType(responseContentType);

                var request = GetRequest(httpReq, restPath);
                if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request)) return;

                var response = GetResponse(httpReq, request);
                if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, response)) return;

                if (responseContentType.Contains("jsv") && !string.IsNullOrEmpty(httpReq.QueryString["debug"]))
                {
                    JsvSyncReplyHandler.WriteDebugResponse(httpRes, response);
                    return;
                }

                if(doJsonp)
                    httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
                else
                    httpRes.WriteToResponse(httpReq, response);
            }
            catch(Exception ex) {
                bool writeErrorToResponse = ServiceStack.Configuration.ConfigUtils.GetAppSetting<bool>(ServiceStack.Configuration.Keys.WriteErrorsToResponse, true);
                if(!writeErrorToResponse) {
                    throw;
                }

                var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);
                Log.Error(errorMessage, ex);

                try {
                    //httpRes.WriteToResponse always calls .Close in it's finally statement so if there is a problem writing to response, by now it will be closed
                    if(!httpRes.IsClosed) {

                        var attrEndpointType = ContentType.GetEndpointAttributes(responseContentType);
                        httpRes.WriteErrorToResponse(attrEndpointType, operationName, errorMessage, ex);
                    }
                }
                catch(Exception WriteErrorEx) {
                    //Exception in writing to response should not hide the original exception
                    Log.Info("Failed to write error to response: {0}", WriteErrorEx);
                    //rethrow the original exception
                    throw ex;
                }
            }
        }
开发者ID:letssellsomebananas,项目名称:ServiceStack,代码行数:60,代码来源:RestHandler.cs

示例8: ProcessRequest

        //public StreamSerializerDelegate GetStreamSerializer(string contentType)
        //{
        //    return GetContentFilters().GetStreamSerializer(contentType);
        //}
        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            try
            {
                EndpointHost.Config.AssertFeatures(usesFeature);

                httpReq.ResponseContentType = httpReq.GetQueryStringContentType() ?? this.HandlerContentType;
                var callback = httpReq.QueryString["callback"];
                var doJsonp = EndpointHost.Config.AllowJsonpRequests
                              && !string.IsNullOrEmpty(callback);

                var request = CreateRequest(httpReq, operationName);
                if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request)) return;

                var response = GetResponse(httpReq, request);
                if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, response)) return;

                if (doJsonp)
                    httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
                else
                    httpRes.WriteToResponse(httpReq, response);
            }
            catch (Exception ex)
            {
                bool writeErrorToResponse = ServiceStack.Configuration.ConfigUtils.GetAppSetting<bool>(ServiceStack.Configuration.Keys.WriteErrorsToResponse, true);
                if(!writeErrorToResponse) {
                    throw;
                }
                var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);
                Log.Error(errorMessage, ex);

                try {
                    //httpRes.WriteToResponse always calls .Close in it's finally statement so if there is a problem writing to response, by now it will be closed
                    if(!httpRes.IsClosed) {
                        httpRes.WriteErrorToResponse(HandlerContentType, operationName, errorMessage, ex);
                    }
                }
                catch(Exception WriteErrorEx) {
                    //Exception in writing to response should not hide the original exception
                    Log.Info("Failed to write error to response: {0}", WriteErrorEx);
                    //rethrow the original exception
                    throw ex;
                }
            }
        }
开发者ID:letssellsomebananas,项目名称:ServiceStack,代码行数:49,代码来源:GenericHandler.cs


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