public void SendError(string msg, int status) { try { var response = _context.Response; response.StatusCode = status; response.ContentType = "text/html"; var description = HttpListenerResponseHelper.GetStatusDescription(status); var str = msg != null ? string.Format("<h1>{0} ({1})</h1>", description, msg) : string.Format("<h1>{0}</h1>", description); var error = _context.Response.ContentEncoding.GetBytes(str); response.Close(error, false); } catch { // response was already closed } }
public void SendError(string msg, int status) { try { HttpListenerResponse response = context.Response; response.StatusCode = status; response.ContentType = "text/html"; string description = HttpListenerResponseHelper.GetStatusDescription(status); string str; if (msg != null) { str = String.Format("<h1>{0} ({1})</h1>", description, msg); } else { str = String.Format("<h1>{0}</h1>", description); } byte [] error = context.Response.ContentEncoding.GetBytes(str); response.Close(error, false); } catch { // response was already closed } }