How do I mimic a WebException 304 error back to browser if I am using HttpListener?
That is I have received a request to my HttpListener, and then obtained the HttpListenerContext, then from this point how would I mimic/arrange for a HTTP "304 Not Modified" response to be effectively sent back to the browser via the HttpListenerContext.response?
EDIT:
I tried the following however I get an error trying to copy WebException.Status to HttpWebResponse.StatusCode (The status code must be exactly three digits). Any ideas on how to correct this?
catch (WebException ex)
{
listenerContext.Response.StatusCode = (int)ex.Status; //ERROR: The status code must be exactly three digits
listenerContext.Response.StatusDescription = ex.Message;
listenerContext.Response.Close();
thanks
StatusDescription
does not accept\n
so its assignment might fail ifex.Message
contains it. Leaking exception message does not seem like a good idea too -- possibly can used as an attack vector in some obscure cases. – Amphipod