Exemplo n.º 1
0
        public override async Task Invoke(IOwinContext context, AppFunc next)
        {
            IRouteBuilder builder = RouteBuilder.Builder;
            var           route   = builder.Resolve(context.Request);

            if (route != null)
            {
                IRouteHandler handler = RouteHandlerFactory.Default.CreateRouteHandler(context, route);

                try
                {
                    await handler.ProcessAsync(context, context.CancellationToken).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    context.Response.Status = Status.Is.InternalServerError;
                    string message = string.Format("Error Message: {0} {1} StackTrace: {2}",
                                                   ex.Message, Environment.NewLine, ex.StackTrace);

                    context.Response.Headers.ContentType = "text/html; charset=UTF-8";
                    await context.Response.WriteAsync(message);
                }
            }
            if (next != null)
            {
                await next(context.Environment);
            }
        }