Asp.net WebAPI HTTP SERVER ERRORS - user breaks the connection - c#

I have a Web.Api project, and I deployed it to Azure Web Sites.
Some times I see many HTTP SERVER ERRORS in dashboard.
Detailed Error Information: Module ManagedPipelineHandler
Notification ExecuteRequestHandler
Handler System.Web.Http.WebHost.HttpControllerHandler Error
Code 0x800703e3 Requested
URL http://test-server:80/api/Statistics/ShowStories Physical
Path D:\home\site\wwwroot\api\Statistics\ShowStories Logon
Method Anonymous Logon User Anonymous
I don't know how to fix it and why it happens.
UPDATE
I found what this happens because user breaks the internet connections, and my question in next: how to catch this problems, maybe create some custom exception handler, and logger this problems, what this 'http server errors' and not show to Azure dashboard?

See this question: ASP.NET Web API OperationCanceledException when browser cancels the request
I think that if you handle OperationCanceledException correctly, the error will not be logged.

Related

Error 520 on asp.net web app in production

Our asp.net web app is returning Error 520 on a page in production though no error in development.
This particular error skips our custom error page and present a different error page with Cloudflare.
As in this image
When you inspect the page, you see
"Error: Promised response from onMessage listener went out of scope"
in console
No error is logged by our logging tools, and we cannot tell why it's skipping our custom error page.
Any direction as to how to solve this?

Why specific response codes are being replaced by 500 Internal Server Error in Production environment?

In my .Net Core 2.2 application, I have a WebAPI controller that may return response codes 400 and 409.
In the development environment, I can see those codes along with the error messages. But when I deploy the application to the production environment (a virtual machine in Azure) I see just 500 errors without any details. Can anybody explain how to force IIS to return the initially sent error responds?
I return the error responds with the code like the following:
return StatusCode((int)HttpStatusCode.BadRequest, new { Message = errorMessage });
Finally, I have turned on the Failed requests tracing and it gave me a clue. The cause was in the fact that the same MIME type was configured twice, one time globally at the IIS level, and the second time at the website level. Once I removed the problematic MIME-type from the website configuration all started working correctly.
If someone have the same problem, I solved in the Error Pages area from IIS configuration. When I tried to click, I received a error with the path of web.config from another project. When I solved this error from web.config, the Error Page open correctly and everything work again.

This page isn’t working .Localhost is currently unable to handle this request. HTTP ERROR 500

This page isn’t working
localhost is currently unable to handle this request.
HTTP ERROR 500
I have published Web API project on IIS with all configurations.
Already tried things:
.Net Core hosting bundle. (added)
and I can see it in IIS target website modules.
IIS settings checked many times.
Note:
API URL is just returning a method which have string return type which is
But when I hit another method which have list return type it shows the message "localhost is currently unable to handle this request".
Without publishing project on IIS it is working perfectly fine.
Default methods controller are working perfectly fine which returns string.
But when I call other methods in the controller it shows error message "Localhost is currently unable to handle the request"
*URL not working (calling default method which returns string)
working URL (calling another method in controller)
1- enable app.UseDeveloperExceptionPage(); in startup.cs file.
Now execption will show in broweser instead of "Localhost is currently unable to handle the request"
Issue was with the connection string after adding userid and password in connection string my issue resolved.
Thanks for your help and guidance.
Make sure this part comes on top in your Configure method in Startup file
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "learning_todo_jwt v1"));
}
If the error code you get is just 500, not 500.x, then this describes what's going on:
The app starts, but an error prevents the server from fulfilling the request.
This error occurs within the app's code during startup or while creating a response. The response may contain no content, or the response may appear as a 500 Internal Server Error in the browser. The Application Event Log usually states that the app started normally. From the server's perspective, that's correct. The app did start, but it can't generate a valid response. Run the app at a command prompt on the server or enable the ASP.NET Core Module stdout log to troubleshoot the problem.
So you need to figure out what went wrong in your app.
There are more troubleshooting steps under the Troubleshoot on IIS section. In my experience, the most useful troubleshooting step is enabling the stdout log in web.config.
<aspNetCore processPath="bin\myapp.exe" stdoutLogEnabled="true" stdoutLogFile=".\stdout" />
That should hopefully show you an error message in that file and you can search for that error.

HttpClient.SendAsync call results in multiple triggers on service side, returns internal server error

I have an ASP.NET Web API deployed on Azure App service.
I am experiencing following error: For one specific business object my Web API's GET method is returning Internal server error, while for other business objects the same GET method is working fine.
When I debugged my Web API it turned out, that valid business object is returned, but… GET method was triggered multiple times (and on client side I see that it is called only once)
This is an excerpt where Web API is called from client code
// Create HTTP transport objects
HttpRequestMessage httpRequest = new HttpRequestMessage();
httpRequest.Method = HttpMethod.Get;
httpRequest.RequestUri = new Uri(url);
// Set Credentials
if (this.Credentials != null)
{
cancellationToken.ThrowIfCancellationRequested();
await this.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
}
HttpResponseMessage httpResponse = await this.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);
Besides - if I try to open that same url from browser (e.g.: https://myservice.com/api/businessObject/xxx) - request is performed only once (as it should) and correct results (Json) is displayed in browser.
Any suggestions what to try to figure why call from client side (for specific object) results in multiple Web API service executions and how to fix this?
My Web API service is deriving from System.Web.Http.ApiController
I got some information from exception, but it doesn't seem to be very helpful
Exception thrown: 'Microsoft.Rest.TransientFaultHandling.HttpRequestWithStatusException' in Microsoft.Rest.ClientRuntime.dll The thread 0x27fc has exited with code 0 (0x0)
EDIT
I got some information from Azure Log stream, but that information does not seam to make sense… because this problem happens for one specific business object (and only when requested from my application - not failing from web browser), other business objects are working fine so I don't see how this could be related to access / web.config file...
IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.
IIS was not able to process configuration for the Web site or application.
The authenticated user does not have permission to use this DLL.
..
Ensure that the NTFS permissions for the web.config file are correct and allow access to the Web servers machine account.
Check the event logs to see if any additional information was logged.
Verify the permissions for the DLL.
Install the .NET Extensibility feature if the request is mapped to a managed handler.
Create a tracing rule to track failed requests for this HTTP status code

How to return errors from a web service with Elmah?

In my WCF web service I use Elmah to protect against unhandled errors and it works great. However, when error happens the caller of the endpoint gets this response:
How can I send the actual unhandled error that Elmah is recording back to the user?
ELMAH doesn't protect against unhandled errors, it just logs when they are happening. The Request Error page shown in the browser is WCfs way of telling you that an error happened. You don't want to publish error details like cookies and stacktrace to the client. Use /elmah.axd to see all of the details of each error.

Categories

Resources