Why my ASP.NET razor page app cannot access a specific endpoint?

Alex Corsega 0 Reputation points
2024-07-22T20:13:11.8566667+00:00

I have an issue with my ASP.NET app where it cannot access a specific endpoint. It throws a 502 error in Azure and a request timed out on my local machine. The endpoint I want to access is the products endpoint. I found that HttpContext.RequestAborted.IsCancellationRequested is set to true after passing through a certain middleware, which I can't identify since it is a built-in middleware and I cannot put a breakpoint on it. I noticed this because I have a custom middleware, and before calling the await _next(httpContext); method, IsCancellationRequested is set to false. However, after it is called, IsCancellationRequested is set to true, which I believe is the main reason for the error. Additionally, I discovered that I can access the products endpoint in incognito mode because IsCancellationRequested is always false whether before or after calling await _next(httpContext);, which is quite strange.

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,400 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 61,491 Reputation points
    2024-07-23T18:49:48.0633333+00:00

    most likely the request is timing out. the timeout is what sets the cancellation token.

    0 comments No comments

  2. Alex Corsega 0 Reputation points
    2024-07-24T22:04:23.6366667+00:00

    I found out what caused the issue. The problem is that the endpoint uses TempData, and the value was too large. It did not cause the application to throw an exception, but instead, it set HttpContext.RequestAborted.IsCancellationRequested to true. It is strange because when we use TempData.Put, it will not throw an exception, but if we use TempData[key], it will throw an exception if the value is too large. So better use TempData[key].

    0 comments No comments