Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

ASP.NET Core 1.1 on IIS returning empty response body for errors

$
0
0

Is there a way to fix this or have I somehow missed a patch that fixes this?

I have an ASP.NET Core 1.1 app that's returning empty response bodies from my exception filter for my 409 error codes. The rub is that I can't reproduce this problem locally or on my dev staging server which uses the same image as our QA server. QA Server is Windows 2012. All hosted on EC2. I have verified that the problem happens even on local machine (altered hosts. file, not by using "localhost"). 

This is my Main in Startup.cs

		public static void Main()
		{
			var cwd = Directory.GetCurrentDirectory();
			var web = "public";

			var host = new WebHostBuilder()
					.UseContentRoot(Directory.GetCurrentDirectory())
					.UseWebRoot(web)
					.UseKestrel()
					.UseIISIntegration()
					.UseStartup<Startup>()
					.Build();

			host.Run();
		}

This is my Exception filter. (We use the GenericHttpException when we want to pass up stuff like the 409 for duplicate entity inserts.)

public class UnicornExceptionFilter : IExceptionFilter
    {
        public async void OnException(ExceptionContext context)
        {
            HttpStatusCode status = HttpStatusCode.InternalServerError;
            String message = String.Empty;




            var exceptionType = context.Exception.GetType();
            if (exceptionType == typeof(NotFoundException))
            {
                message = context.Exception.Message;
                status = HttpStatusCode.NotFound;
            }
            if (exceptionType == typeof(BadRequestException))
            {
                message = context.Exception.Message;
                status = HttpStatusCode.BadRequest;
            }
            if (exceptionType == typeof(GenericHttpException))
            {
                message = context.Exception.Message;
                status = (context.Exception as GenericHttpException).HttpStatusCode;
            }
            else
            {
                message = context.Exception.Message;
            }

            HttpResponse response = context.HttpContext.Response;
            response.StatusCode = (int)status;
            response.ContentType = "application/json";
            var err = message ;

            await response.WriteAsync(JsonConvert.SerializeObject(new { message= err }));

        }
    }

I have already tried adding HttpErrors Passthrough to web.config as well as CustomErrors off. These steps did not resolve the issue. I've also tried messing with ExceptionHandled as described in this thread https://github.com/aspnet/Mvc/issues/5594 with no success. Also note that this is for our RESTful endpoints and not for MVC Razor views. 

In our local Windows 10 IIS Express and Dev staging Windows Server 2012 IIS, the response body still returns. Our QA/staging environment has the same base image as Dev staging and uses the same publish script and release configuration.  Thanks


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>