Linked Questions

91 votes
7 answers
59k views

In ASP.NET MVC 5 you could throw a HttpException with a HTTP code and this would set the response like so: throw new HttpException((int)HttpStatusCode.BadRequest, "Bad Request."); HttpException does ...
Muhammad Rehan Saeed's user avatar
47 votes
7 answers
76k views

I have an ASP.NET Core 1.0 Web API application and trying to figure out how to pass the exception message to the client if a function that my controller is calling errors out. I have tried so many ...
Blake Rivell's user avatar
25 votes
1 answer
20k views

I would like to return only standardized error responses from my Web API (Asp.net Core 2.1), but I can't seem to figure out how to handle model binding errors. The project is just created from the "...
Brian's user avatar
  • 38.2k
32 votes
2 answers
51k views

I have asp.net core application. The implementation of configure method redirects the user to "Error" page when there is an exception ( in non Development environment) However it only works if the ...
LP13's user avatar
  • 34.8k
21 votes
1 answer
10k views

I'm trying to use the DefaultHttpContext object to unit test my exception handling middleware. My test method looks like this: [Fact] public async Task ...
Chris's user avatar
  • 8,522
17 votes
2 answers
38k views

In Framework WebAPI 2, I have a controller that looks like this: [Route("create-license/{licenseKey}")] public async Task<LicenseDetails> CreateLicenseAsync(string licenseKey, ...
rianjs's user avatar
  • 7,974
15 votes
4 answers
15k views

I have in my startup.cs file: if (env.IsDevelopment()) { app.UseExceptionHandler("/api/error/error-local-development"); } else { app....
edelwater's user avatar
  • 2,852
9 votes
3 answers
21k views

I am trying to use middleware for exception handling in my ASP.Net Core 3.0 Web API project: public class ErrorHandlingMiddleware { private readonly RequestDelegate next; public ...
Eutherpy's user avatar
  • 4,581
2 votes
2 answers
5k views

I'm playing a bit with ASP.NET Core. I'm creating a basic webapi. I'd like to show a JSON error when there is a problem. The printscreen shows want I want on my screen. The only problem is that it's ...
ErazerBrecht's user avatar
  • 1,633
3 votes
3 answers
6k views

I have a .NET Core web app which has an API. I've defined an Middleware class based on this answer like so: public class ErrorHandlingMiddleware { private readonly RequestDelegate next; ...
mellis481's user avatar
  • 4,235
3 votes
3 answers
4k views

I am looking for help we can have a custom Error404 page in ASP.NET 5 MVC6. The closest I have come is to use app.UseStatusCodePagesWithReExecute("/Error/{0}"); in the Startup.cs Configure method. ...
Vijay Bhatter's user avatar
3 votes
3 answers
3k views

I have a traditional WebApi project on .NET 4.6.1 with a global ExceptionFilter which handles known exceptions to return a friendly message with a corresponding status code. WebApiConfig.cs public ...
Kevin Aung's user avatar
1 vote
1 answer
4k views

I do not know if this is actually possible, but I think it' s worth a try to find out. There are maybe other and better patterns (if you know one let me know, I will look them up) to do this, but I'm ...
botenvouwer's user avatar
  • 4,472
6 votes
1 answer
3k views

I have a simple Web API Core v3.1 where I am trying to handle Exceptions Globally. After following this answer https://stackoverflow.com/a/55166404/1508398, here is my code for doing that. app....
bit's user avatar
  • 4,497
3 votes
1 answer
5k views

When the code in the startup class throws, ASP.NET Core catches the exception instead of letting it fall through behind the IWebHost.Build call. The app consequently does start but only serves an ...
John's user avatar
  • 7,119

15 30 50 per page