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 } }
internal HttpResponse(HttpStatusCode code) : this((int)code, HttpListenerResponseHelper.GetStatusDescription((int)code), HttpVersion.Version11, new NameValueCollection()) { }
internal HttpResponse(HttpStatusCode code) : this(code, HttpListenerResponseHelper.GetStatusDescription((int)code)) { }