コード例 #1
0
        public static void SendException(this IHttpListenerContext context, WebDavException ex)
        {
            context.Response.StatusCode = ex.StatusCode;
            context.Response.StatusDescription = ex.StatusDescription;

            if (ex.Message == context.Response.StatusDescription)
                return;

            byte[] buffer = Encoding.UTF8.GetBytes(ex.Message);
            context.Response.ContentEncoding = Encoding.UTF8;
            context.Response.ContentLength64 = buffer.Length;
            context.Response.OutputStream.Write(buffer, 0, buffer.Length);
            context.Response.OutputStream.Flush();
        }
コード例 #2
0
 private void SendResponseForException(IHttpListenerContext context, WebDavException ex)
 {
     try
     {
         context.Response.StatusCode = ex.StatusCode;
         context.Response.StatusDescription = ex.StatusDescription;
         var response = ex.GetResponse(context);
         if (!(context.Request.HttpMethod == "HEAD"))
         {
             if (response != context.Response.StatusDescription)
             {
                 byte[] buffer = Encoding.UTF8.GetBytes(response);
                 context.Response.ContentEncoding = Encoding.UTF8;
                 context.Response.ContentLength64 = buffer.Length;
                 context.Response.OutputStream.Write(buffer, 0, buffer.Length);
                 context.Response.OutputStream.Flush();
             }
         }
         context.Response.Close();
     }
     catch (Exception innerEx)
     {
         _log.Error("Exception cannot be returned to caller: " + ex.Message, ex);
         _log.Error("Unable to send response for exception: " + innerEx.Message, innerEx);
     }
    
 }