Ejemplo n.º 1
0
        //public IPrincipal User { get; private set; }

        public HttpRequestContext(HttpAsyncHost hostContext, HttpListenerContext listenerContext)
        {
            HostContext = hostContext;
            Request     = listenerContext.Request;
            Response    = listenerContext.Response;
            //User = listenerContext.User;
        }
        static async Task ProcessListenerContext(HttpListenerContext listenerContext, HttpAsyncHost host)
        {
            Debug.Assert(listenerContext != null);

            try
            {
                // Get the response action to take:
                var requestContext = new HttpRequestContext(host, listenerContext);
                await host._handler.Execute(requestContext);

                // Close the response and send it to the client:
                listenerContext.Response.Close();
            }
            catch (HttpListenerException)
            {
                // Ignored.
            }
            catch (Exception ex)
            {
                // TODO: better exception handling. we should probably return an internal server error HTTP code.
                Trace.WriteLine(ex.ToString());
            }
        }