ErrorHandling Middleware catch is never caught - c#

I have this ErrorHandlingMiddleware that looks like this:
public class ErrorHandlingMiddleware
{
private readonly RequestDelegate _next;
public ErrorHandlingMiddleware(RequestDelegate next)
{
this._next = next;
}
public async Task Invoke(HttpContext context /* other dependencies */)
{
try
{
await _next(context);
}
catch (Exception ex)
{
await HandleExceptionAsync(context, ex);
}
}
private static Task HandleExceptionAsync(HttpContext context, Exception ex)
{
var statusCode = (int)HttpStatusCode.InternalServerError;
if (ex is NotFoundError) statusCode = (int)HttpStatusCode.NotFound;
//else if (ex is MyUnauthorizedException) code = HttpStatusCode.Unauthorized;
//else if (ex is MyException) code = HttpStatusCode.BadRequest;
var error = new AttemptError(statusCode, ex.Message, ex);
context.Response.ContentType = "application/json";
context.Response.StatusCode = statusCode;
return context.Response.WriteAsync(error.ToString());
}
}
And I have added this to my Startup class:
public void Configure(IApplicationBuilder app)
{
app.UseMiddleware<ErrorHandlingMiddleware>();
app.SeedIdentityServerDatabase();
app.UseDeveloperExceptionPage();
app.UseIdentityServer();
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "r3plica Identity Server v1");
c.OAuthClientId("swagger");
c.OAuthAppName("Swagger Api UI");
});
app.UseMvc();
}
I would expect that if I was anywhere in my application and I throw an exception, it would be caught and it would execute this line:
await HandleExceptionAsync(context, ex);
So, I set up a test:
throw new Exception();
Which is thrown in my controller. When I run my application and then call the endpoint that has that exception thrown, it does indeed get to the Invoke method of my ErrorHandlingMiddleware, but instead of an exception being caught, it just goes to the await _next(context)....
Does anyone know what I am doing wrong?

Your middleware will work if you place the call to use it after app.UseDeveloperExceptionPage(); in Startup.
Handle errors in ASP.NET Core says
Place the call to UseDeveloperExceptionPage before any middleware that you want to catch exceptions.

I fixed this by creating a filter:
public class HttpResponseExceptionFilter : IActionFilter, IOrderedFilter
{
public int Order { get; set; } = int.MaxValue - 10;
public void OnActionExecuting(ActionExecutingContext context) { }
public void OnActionExecuted(ActionExecutedContext context)
{
if (context.Exception == null) return;
var attempt = Attempt<string>.Fail(context.Exception);
if (context.Exception is AttemptException exception)
{
context.Result = new ObjectResult(attempt)
{
StatusCode = exception.StatusCode,
};
}
else
{
context.Result = new ObjectResult(attempt)
{
StatusCode = (int)HttpStatusCode.InternalServerError,
};
}
context.ExceptionHandled = true;
}
}
And registering it like this:
services.AddControllers(options => options.Filters.Add(new HttpResponseExceptionFilter()));

Related

Catch Exception and respond with custom message without skipping OutputFormatter

I am developing WebAPI and want to catch all my ApiException custom exceptions and display WebAPI-friendly responses. The ApiException exception can be thrown from Action or Filter like IAuthorizationFilter or ActionFilterAttribute.
First I tried to use IExceptionFilter but later I found that the IExceptionFilter handles only exceptions thrown from Actions and not from other Filters.
public class ApiExceptionFilter : IExceptionFilter
{
public void OnException(ExceptionContext context)
{
var exception = context.Exception;
if (exception is not ApiException responseException)
{
responseException = new ApiException(ResponseMessageType.UnhandledException);
}
context.Result = new ObjectResult(new ResultMessageDto(responseException))
{
StatusCode = responseException.HttpStatusCode
};
}
}
The second approach that I found many suggest to use is the Middleware but this is not the correct way by WebAPI design.
public class ErrorHandlerMiddleware
{
private readonly RequestDelegate _next;
public ErrorHandlerMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
try
{
await _next(context);
}
catch (Exception exception)
{
var response = context.Response;
response.ContentType = "application/json";
if (exception is not ApiException responseException)
{
responseException = new ApiException(ResponseMessageType.UnhandledException);
}
response.StatusCode = responseException.HttpStatusCode;
await response.WriteAsJsonAsync(new ResultMessageDto(responseException), new JsonSerializerOptions()
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
PropertyNamingPolicy = null
});
}
}
}
The Middleware exception handling skips WebAPI MVC OutputFormaters and responds only in JSON or what is set by the developer. This solution is bad by design because do not respect Accept header.
How to handle Exceptions in Actions and Filters without leaving MVC scope?
I feel it is best to handle in Middleware, Here is a sample code. I am using Json but over here, you can use any output formatter (even custom ones).
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
try
{
await next(context);
}
catch (Exception ex)
{
await HandleExceptionAsync(context, ex);
}
}
private async Task HandleExceptionAsync(HttpContext context, Exception exception)
{
int statusCode = StatusCodes.Status500InternalServerError;
string exceptionType, exceptionDetail;
context.Response.ContentType = "application/json";
switch (exception)
{
case ArgumentNullException:
exceptionType = "Argument Null Exception";
exceptionDetail = exception.Message;
break;
case ApiException:
exceptionType = "API Exception";
exceptionDetail = exception.Message;
break;
default:
exceptionType = "Unhandled"
exceptionDetail = "Something went wrong";
break;
}
var problemDetails = new Microsoft.AspNetCore.Mvc.ProblemDetails
{
Status = statusCode,
Type = exceptionType,
Title = "An error has occurred within the PromComm Application",
Detail = exceptionDetail,
Instance = context.Request.Path
};
// You can use any formatter here even with custom messages
var problemDetailsJson = System.Text.Json.JsonSerializer.Serialize(problemDetails);
context.Response.StatusCode = statusCode;
await context.Response.WriteAsync(problemDetailsJson);
}

How to create custom Exception and Error handler in .Net Core?

I develop a .NET Core 3 REST API using C#.
I read a lot about this topic, and I implemented a custom exception handler middleware, which is work well.
But I realized that the error messages are structured differently.
For example, I use .Net Core Identity and when I try to save a username which is already saved, then I get an HTTP 400 with the following error response: (Sorry about that, I can't post images.)
error Array(1){
0: {
code: "...",
description: ".."
}
}
And, I use too the Attribute validation, which gives this HTTPErrorResponse:
error: {
.
.
.
errors:{
Password: Array(1) {
0: "The field..."
}
}
}
Finally, my custom exception handler class gives an ErroDTO which contains a Code, and a description.
So the problem is there are 3 things, which give 3 different error responses, and I don't know how can I handle this, in Frontend which is an Angular project.
I would like to handle all errors and exceptions by my ErroDto class, but I don't know how to transform the Identity or Attribute errors.
I think that I could test the email and password validation directly in the endpoint instead of using Attribute, and I could test if the existing email, and the Identity won't be throw error. But I think it is not the best practice, and it will be a lot of boilerplate code.
This is my exception handling class:
public class ErrorHandlingMiddleware
{
private readonly RequestDelegate next;
public ErrorHandlingMiddleware(RequestDelegate next)
{
this.next = next;
}
public async Task Invoke(HttpContext context /* other dependencies */)
{
try
{
await next(context);
}
catch (Exception ex)
{
await HandleExceptionAsync(context, ex);
}
}
private static Task HandleExceptionAsync(HttpContext context, Exception ex)
{
var code = HttpStatusCode.InternalServerError; // 500 if unexpected
ErrorDto error = new ErrorDto();
if (ex is WrongCredentialsException)
{
code = HttpStatusCode.OK;
WrongCredentialsException wrongCredentialsException = (WrongCredentialsException) ex;
error.Code = wrongCredentialsException.Code;
error.Description = wrongCredentialsException.Message;
}
var result = JsonConvert.SerializeObject(new { error });
context.Response.ContentType = "application/json";
context.Response.StatusCode = (int)code;
return context.Response.WriteAsync(result);
}
}
Create custom Exception class
using System;
[Serializable]
public class EmployeeMgmtException : Exception
{
public EmployeeMgmtException(string message) : base(message)
{
}
}
Create an Exception Middleware class
public class ExceptionMiddleware
{
private readonly RequestDelegate next;
private readonly ILogger<ExceptionMiddleware> logger;
private readonly ResourceManager resourceManager;
}
public ExceptionMiddleware(RequestDelegate next, ILogger<ExceptionMiddleware>
logger)
{
this.next = next;
this.logger = logger;
this.resourceManager = new
ResourceManager("EmployeeException.API.Resources.Resource",
typeof(ExceptionMiddleware).Assembly);
}
public async Task InvokeAsync(HttpContext httpContext)
{
try
{
await this.next.Invoke(httpContext);
}
catch (Exception ex)
{
await this.HandleExceptionAsync(httpContext, ex);
}
}
private Task HandleExceptionAsync(HttpContext context, Exception exception)
{
context.Response.ContentType = "application/json";
ErrorResponse response = new ErrorResponse();
if (exception is EmployeeMgmtException)
{
context.Response.StatusCode = (int)HttpStatusCode.OK;
response.ErrorMessage = exception.Message;
}
else
{
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
response.ErrorMessage = this.resourceManager.GetString("FailedToProcess",
CultureInfo.CurrentUICulture);
}
this.logger.LogCritical(exception, exception.Message, GetProperties(context));
return context.Response.WriteAsync(response.ToString());
}
}
Register Exception Middleware filter in Startup.cs
app.UseMiddleware<ExceptionMiddleware>();

Getting empty response on ASP.NET Core middleware on exception

I am trying to create a middleware that can log the response body as well as manage exception globally and I was succeeded about that. My problem is that the custom message that I put on exception it's not showing on the response.
Middleware Code 01:
public async Task Invoke(HttpContext context)
{
context.Request.EnableRewind();
var originalBodyStream = context.Response.Body;
using (var responseBody = new MemoryStream())
{
try
{
context.Response.Body = responseBody;
await next(context);
context.Response.Body.Seek(0, SeekOrigin.Begin);
var response = await new StreamReader(context.Response.Body).ReadToEndAsync();
context.Response.Body.Seek(0, SeekOrigin.Begin);
// Process log
var log = new LogMetadata();
log.RequestMethod = context.Request.Method;
log.RequestUri = context.Request.Path.ToString();
log.ResponseStatusCode = context.Response.StatusCode;
log.ResponseTimestamp = DateTime.Now;
log.ResponseContentType = context.Response.ContentType;
log.ResponseContent = response;
// Keep Log to text file
CustomLogger.WriteLog(log);
await responseBody.CopyToAsync(originalBodyStream);
}
catch (Exception ex)
{
context.Response.ContentType = "application/json";
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
var jsonObject = JsonConvert.SerializeObject(My Custom Model);
await context.Response.WriteAsync(jsonObject, Encoding.UTF8);
return;
}
}
}
If I write my middleware like that, my custom exception is working fine but I unable to log my response body.
Middleware Code 02:
public async Task Invoke(HttpContext context)
{
context.Request.EnableRewind();
try
{
await next(context);
}
catch (Exception ex)
{
context.Response.ContentType = "application/json";
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
var jsonObject = JsonConvert.SerializeObject(My Custom Model);
await context.Response.WriteAsync(jsonObject, Encoding.UTF8);
return;
}
}
My Controller Action :
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
throw new Exception("Exception Message");
}
Now I want to show my exception message with my middleware 01, but it doesn't work but its work on my middleware 02.
So my observation is the problem is occurring for reading the context response. Is there anything I have missed in my middleware 01 code?
Is there any better way to serve my purpose that log the response body as well as manage exception globally?
I think what you are saying is that this code isn't sending it's response to the client.
catch (Exception ex)
{
context.Response.ContentType = "application/json";
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
var jsonObject = JsonConvert.SerializeObject(My Custom Model);
await context.Response.WriteAsync(jsonObject, Encoding.UTF8);
return;
}
The reason for this is that await context.Response.WriteAsync(jsonObject, Encoding.UTF8); isn't writing to the original body stream it's writing to the memory stream that is seekable. So after you write to it you have to copy it to the original stream. So I believe the code should look like this:
catch (Exception ex)
{
context.Response.ContentType = "application/json";
context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
var jsonObject = JsonConvert.SerializeObject(My Custom Model);
await context.Response.WriteAsync(jsonObject, Encoding.UTF8);
context.Response.Body.Seek(0, SeekOrigin.Begin); //IMPORTANT!
await responseBody.CopyToAsync(originalBodyStream); //IMPORTANT!
return;
}
There is a wonderful article explaining in detail your problem - Using Middleware to trap Exceptions in Asp.Net Core.
What you need to remember about middleware is the following:
Middleware is added to your app during Startup, as you saw above. The order in which you call the Use... methods does matter! Middleware is "waterfalled" down through until either all have been executed, or one stops execution.
The first things passed to your middleware is a request delegate. This is a delegate that takes the current HttpContext object and executes it. Your middleware saves this off upon creation, and uses it in the Invoke() step.
Invoke() is where the work is done. Whatever you want to do to the request/response as part of your middleware is done here. Some other usages for middleware might be to authorize a request based on a header or inject a header in to the request or response
So what you do, you write a new exception type, and a middleware handler to trap your exception:
New Exception type class:
public class HttpStatusCodeException : Exception
{
public int StatusCode { get; set; }
public string ContentType { get; set; } = #"text/plain";
public HttpStatusCodeException(int statusCode)
{
this.StatusCode = statusCode;
}
public HttpStatusCodeException(int statusCode, string message) : base(message)
{
this.StatusCode = statusCode;
}
public HttpStatusCodeException(int statusCode, Exception inner) : this(statusCode, inner.ToString()) { }
public HttpStatusCodeException(int statusCode, JObject errorObject) : this(statusCode, errorObject.ToString())
{
this.ContentType = #"application/json";
}
}
And the middlware handler:
public class HttpStatusCodeExceptionMiddleware
{
private readonly RequestDelegate _next;
private readonly ILogger<HttpStatusCodeExceptionMiddleware> _logger;
public HttpStatusCodeExceptionMiddleware(RequestDelegate next, ILoggerFactory loggerFactory)
{
_next = next ?? throw new ArgumentNullException(nameof(next));
_logger = loggerFactory?.CreateLogger<HttpStatusCodeExceptionMiddleware>() ?? throw new ArgumentNullException(nameof(loggerFactory));
}
public async Task Invoke(HttpContext context)
{
try
{
await _next(context);
}
catch (HttpStatusCodeException ex)
{
if (context.Response.HasStarted)
{
_logger.LogWarning("The response has already started, the http status code middleware will not be executed.");
throw;
}
context.Response.Clear();
context.Response.StatusCode = ex.StatusCode;
context.Response.ContentType = ex.ContentType;
await context.Response.WriteAsync(ex.Message);
return;
}
}
}
// Extension method used to add the middleware to the HTTP request pipeline.
public static class HttpStatusCodeExceptionMiddlewareExtensions
{
public static IApplicationBuilder UseHttpStatusCodeExceptionMiddleware(this IApplicationBuilder builder)
{
return builder.UseMiddleware<HttpStatusCodeExceptionMiddleware>();
}
}
Then use your new middleware:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseHttpStatusCodeExceptionMiddleware();
}
else
{
app.UseHttpStatusCodeExceptionMiddleware();
app.UseExceptionHandler();
}
app.UseStaticFiles();
app.UseMvc();
}
The end use is simple:
throw new HttpStatusCodeException(StatusCodes.Status400BadRequest, #"You sent bad stuff");

Show exception created in EF Core repository instead of 500 Error

My goal is to verify if an object's name already exists in my EF Core db, if so: throw a specific error. However, I receive a 500 internal server error.
First I created an index on name in DbContext, including IsUnique and some code to catch the exception in the repository.
Can I maybe add something in the controller that says if errorcode == 2601 then throw "the required exception"? Or is there another way to overcome this 500 error? Thanks in advance for the help!
DbContext:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Car>()
.HasIndex(c => c.Name)
.IsUnique();
}
Repository:
public async Task<bool> SaveAsync()
{
try
{
return (await _context.SaveChangesAsync() >= 0);
}
catch (DbUpdateException dbEx)
{
SqlException sqlException = dbEx.InnerException as SqlException;
if (sqlException.Number == 2601)
{
throw new Exception("Name already exists. Please provide a different name.");
}
throw new Exception(dbEx.Message);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
Controller:
Public async Task<IActionResult> AddCar([FromBody] Car car)
...
if (!await _repository.SaveAsync())
{
throw new Exception("Fail on save...");
}
...
If you are using ASP.Net Core, you can create you own exception handling middleware.
The error handling middleware class itself may look something like:
public class ExceptionHandlingMiddleware
{
private readonly RequestDelegate m_next;
public ErrorHandlingMiddleware(RequestDelegate next)
{
m_next = next;
}
public async Task Invoke(HttpContext context /* other dependencies */)
{
try
{
await m_next(context);
}
catch (Exception ex)
{
await HandleExceptionAsync(context, ex);
}
}
private static Task HandleExceptionAsync(HttpContext context, Exception exception)
{
HttpStatusCode httpStatusCode = HttpStatusCode.InternalServerError;
string message = "Something is wrong!";
if (exception is MyException)
{
httpStatusCode = HttpStatusCode.NotFound; // Or whatever status code you want to return
message = exception.Message; // Or whatever message you want to return
}
string result = JsonConvert.SerializeObject(new
{
error = message
});
context.Response.StatusCode = (int)httpStatusCode;
context.Response.ContentType = "application/json";
return context.Response.WriteAsync(result);
}
}
You register in Startup.Configure() as:
app.UseMiddleware(typeof(ErrorHandlingMiddleware));
Change stdoutLogEnabled="false" to true and then check the logs at stdoutLogFile=".\logs\stdout". The error(s) there might tell you something.
Check that you set up right Environment Name using ASPNETCORE_ENVIRONMENT environment variable as so use correct settings like connection string. On your machine by default you have "Development" environment.
You may use Error Handling middlewares for showing exceptions like
app.UseDeveloperExceptionPage();

ASP.NET Core Web API Throws HTTP 500

I've created a new ASP.NET Core Web API and have several controllers such as this one:
[Route("api/[controller]")]
public class DoctorRevenueController : Controller
{
private IDoctorRevenueRepository DoctorRevenueRepository;
public DoctorRevenueController(IDoctorRevenueRepository repository)
{
DoctorRevenueRepository = repository;
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
}
[HttpGet("GetDoctorRevenues")]
//[Route("DoctorRevenue")]
public async Task<IActionResult> GetDoctorRevenues(Int32? pageSize = 10, Int32? pageNumber = 1, String DoctorName = null)
{
var response = new ListModelResponse<DocRevViewModel>() as IListModelResponse<DocRevViewModel>;
try
{
response.PageSize = (Int32)pageSize;
response.PageNumber = (Int32)pageNumber;
response.Model = await Task.Run(() =>
{
return DoctorRevenueRepository
.GetDocRevenues(response.PageNumber, response.PageSize, DoctorName)
.Select(item => item.ToViewModel())
.ToList();
});
response.Message = String.Format("Total Records {0}", response.Model.Count());
}
catch (Exception ex)
{
response.DidError = true;
response.Message = ex.Message;
}
return response.ToHttpResponse();
}
//GET DoctorRevenues/Doctor
[HttpGet("GetDoctorRevenue/{DoctorId}")]
//[Route("DoctorRevenue")]
public async Task<IActionResult> GetDoctorRevenue(int DoctorId)
{
var response = new SingleModelResponse<DocRevViewModel>() as ISingleModelResponse<DocRevViewModel>;
try
{
response.Model = await Task.Run(() =>
{
return DoctorRevenueRepository.GetDocRevenue(DoctorId).ToViewModel();
});
}
catch (Exception ex)
{
response.DidError = true;
response.Message = ex.Message;
}
return response.ToHttpResponse();
}
//POST DoctorRevenues/Doctor
[HttpPost("CreateDoctorRevenue/{DoctorId}")]
//[Route("DoctorRevenue")]
public async Task<IActionResult> CreateDoctorRevenue([FromBody]DocRevViewModel value)
{
var response = new SingleModelResponse<DocRevViewModel>() as ISingleModelResponse<DocRevViewModel>;
try
{
var entity = await Task.Run(() =>
{
return DoctorRevenueRepository.AddDocRevenue(value.ToEntity());
});
response.Model = entity.ToViewModel();
response.Message = "The invoices and revenue for this doctor have been successfully saved.";
}
catch(Exception ex)
{
response.DidError = true;
response.Message = ex.Message;
}
return response.ToHttpResponse();
}
//PUT DoctorRevenues/Doctor/5
[HttpPut("UpdateDoctorRevenue/{RecordId}")]
//[Route("DoctorRevenue/{RecordId}")]
public async Task<IActionResult> UpdateDoctorRevenue(int RecordId, [FromBody]DocRevViewModel value)
{
var response = new SingleModelResponse<DocRevViewModel>() as ISingleModelResponse<DocRevViewModel>;
try
{
var entity = await Task.Run(() =>
{
return DoctorRevenueRepository.UpdateDocRevenue(RecordId, value.ToEntity());
});
response.Model = entity.ToViewModel();
response.Message = "The invoices and revenue for this doctor were successfully updated.";
}
catch(Exception ex)
{
response.DidError = true;
response.Message = ex.Message;
}
return response.ToHttpResponse();
}
//DELETE DoctorRevenue/5
[HttpDelete]
[Route("DoctorRevenue/{RecordId}")]
public async Task<IActionResult> DeleteDoctorRevenue(int RecordId)
{
var response = new SingleModelResponse<DocRevViewModel>() as ISingleModelResponse<DocRevViewModel>;
try
{
var entity = await Task.Run(() =>
{
return DoctorRevenueRepository.DeleteDocRevenue(RecordId);
});
response.Message = "This doctor's invoices and revenue have been deleted";
}
catch(Exception ex)
{
response.DidError = true;
response.Message = ex.Message;
}
return response.ToHttpResponse();
}
}
My Startup.cs includes:
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IDoctorMasterRepository, DoctorMasterRepository>();
services.AddScoped<IDoctorRevenueRepository, DoctorRevenueRepository>();
services.AddScoped<IFacilityMasterRepository, FacilityMasterRepository>();
services.AddScoped<IFacilityRevenueRepository, FacilityRevenueRepository>();
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
services.AddMvc();
services.AddOptions();
services.AddLogging();
services.AddSingleton<IDoctorMasterRepository, DoctorMasterRepository>();
services.AddSingleton<IFacilityMasterRepository, FacilityMasterRepository>();
services.AddSingleton<IDoctorRevenueRepository, DoctorRevenueRepository>();
services.AddSingleton<IFacilityRevenueRepository, FacilityRevenueRepository>();
services.AddSwaggerGen();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseStaticFiles();
app.UseDeveloperExceptionPage();
app.UseApplicationInsightsRequestTelemetry();
app.UseApplicationInsightsExceptionTelemetry();
app.UseMvc();
app.UseSwagger();
app.UseSwaggerUi();
}
After successfully building the project, a Debug produces an error:
localhost refused to connect. ERR_CONNECTION_REFUSED
How do I remedy this such that I can view my API documentation page?
I found that dotnet run needed to be executed at the command line to start the local IISExpress platform. After doing so, Postman served my API routes as expected.

Categories

Resources