public void SendError(string msg, int status)
{
try
{
HttpListenerResponse response = _context.Response;
response.StatusCode = status;
response.ContentType = "text/html";
string description = HttpStatusDescription.Get(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
}
}