My project has an error page called oops.aspx. We have the following code in global.asax:
protected void Application_Error(object sender, EventArgs e)
{
Server.Transfer("~/oops.aspx", true);
}
oops.aspx is able to extract the error, generate a nice email to the server, and present an error message to the user.
The use of Server.Transfer preserves the URL, form information, and other helpful troubleshooting information. At one point in the oops.aspx, while composing the email, I grab Request.RawUrl and include it in the email. This is the URL (with query string parameters) of the page that caused the error.
We also have this in web.config:
<customErrors mode="On" defaultRedirect="oops.aspx"></customErrors>
When the system redirects because of an error based on this, it redirects to /oops.aspx?aspxerrorpath=/Clients/EditClient.aspx (sometimes with /, sometimes with %2f path separators). Querystring and Exception information is lost, so the email and messages generated by oops.aspx are sparse and don't say much about what was happening.
I've been getting a lot of errors of this second kind lately. The errors happen in small bunches, several of them in a few minutes, and then nothing for several hours. They happen all over the site (including on WebResource.axd and the like), which makes me think that it's not a specific error in our site but something happening at a lower level, like a Session server issue or something like that.
So, with all that, my actual question:
I'm having errors in the site that happen in such a way that they are not caught by global.asax. What can cause such errors, and how can I troubleshoot them?
Since you have enabled custom errors in your web.config, the exception will be caught before the Application_Error executes and redirect you to oops.aspx. If you don't want this from happening do not enable custom errors in your web.config. This way all errors will go through Application_Error assuming you have configured IIS to run the application pool in Integrated pipeline mode.
Related
We got the following problem:
I am currently developing a web server implementing a specific API. The association behind that API provided specific test cases I'm using to test my implementation.
One of the test cases is:
5.3.2.12 Robustness, large resource ID
This test confirms correct error handling when sending a HTTP request with a very long location ID as URL parameter.
The url its calling looks something like this:
https://localhost:443/api/v2/functions/be13789-1f1e-47d0-8f8a-000000000005ebe13789-1f1e-47d0-8f8a-000000000005ebe13789-1f1e-47d0-8f8a-000000000005ebe13789-1f1e-47d0-8f8a-000000000005ebe13789-1f1e-47d0-8f8a-000000000005ebe13789-1f1e-47d0-8f8a-000000000005ebe13789-1f1e-47d0-8f8a-000000000005ebe13789-1f1e-47d0-8f8a-000000000005ebe13789-1f1e-47d0-8f8a-000000000005ebe13789-1f1e-47d0-8f8a-000000000005ebe13789-1f1e-47d0-8f8a-000000000005ebe13789-1f1e-47d0-8f8a-000000000005ebe13789-1f1e-47d0-8f8a-000000000005ebe13789-1f1e-47d0-8f8a-000000000005ebe13789-1f1e-47d0-8f8a-000000000005ebe13789-1f1e-47d0-8f8a-000000000005ebe13789-1f1e-47d0-8f8a-000000000005ebe13789-1f1e-47d0-8f8a-000000000005ebe13789-1f1e-47d0-8f8a-000000000005ebe13789-1f1e-47d0-8f8a-000000000005
Basically the tests checks, if my server responds with the correct error code if the URL is too long. (At the time of writing it is testing for Errorcode 405, but I already asked them if it shouldn't be 414)
I'm developing the server in Asp.Net 6 and it always returns Bad Request 400 in the testcase.
I don't seem to find a place to change the handling for this behaviour and I am not even sure, if I can, or if the IIS is blocking the request even before it reaches my server. I activated logging in IIS, but the request does not show in the logfile in inetpub/logs/LogFiles.
My question would be, if it is possible to tell IIS to return a different error code in this case, or if it is even possible to handle the error in my application.
What I tried:
Activating IIS Logs to see if the request is even passed to my site. (It did not)
Tried adding Filters to my Controller to see if I can catch an Exception
Checked, if Development Error Sites are called.
Breakpoints in existing middlewares are not reached.
EDIT:
I am now pretty sure now, that the request never reaches my application.
It is possible to reproduce the error by using the default site the IIS generates on windows. Just copy the whole path from above into a browser with the host http://localhost will also just produce the error 400
EDIT 2:
As #YurongDai pointed out, I tried activating failed request tracing for my IIS Site. I used the default path \logs\FailedReqLogFiles.
The folder was created, but no file is written, when I'm opening the URL above in my browser.
IIS Error 400 occurs when the server is unable to process a request sent to a web server. The most common cause of Bad Request error 400 is an invalid URL, but it can happen for other reasons as well. To resolve IIS Error 400, first make sure that you have entered the URL correctly, typos or disallowed characters in the URL are the most common causes of Bad Request errors. If the error persists after verifying the URL, please clear your browser's cache, DNS cache, and cookies and try again.
Clear your browser's cookies.
Clear your browser's cache.
Clear your DNS cache.(Execute the following command in the command prompt window: ipconfig /flushdns)
I'm trying to serve a custom "site down" page instead of the standard YSOD if the server were ever to fail during it's startup. Using <customErrors> inside of web.Config work's fine for any server error occurring after startup has completed successfully, but in this case the YSOD response is not replaced.
Other resources have lead me to adding app_offline.htm to the root of the project and playing with its name during deployment, but this does not tackle unexpected server issues occurring during startup.
Is there a way to serve a "default" page if there are any errors or a proper HTTP response could not be formed?
Yes there is a way to do that but that depends how you want to handle those errors.
If you want to redirect to the same error page on any 4xx or 5xx status codes then you can use the below code in your web.config file
<customErrors mode="On" defaultRedirect="Error.aspx">
</customErrors>
In error page you can display some user friendly message.
I have a very weird problem.
I have a development environment where I develop a ASP.NET MVC Application, in this environment everything works. Especially in the Application there is a certain AJAX call which calls on a controller and passes data, the controller just needs to update the database with the passed information.Everything works!.
However I hop onto the server with everything setup just as development environment(database,connection strings all that). An everything works fine, login functions as well as other database saving functions and controller actions seems to work fine. Except for ONE controller that return a 500 Internal Server Error.
I asked around and everyone wants to see the logs.
In the event viewer there are no logs pertaining to this 500 Internal Server Error.
IIS logs however did provide something,but the information does not give specifics on what is causing the 500 Internal Server Error.
I know what a 500 Internal Server Error is and I know its a generic error for a variety of problems, however after looking at the logs I cannot figure out why this specific controller action is giving a 500 error when it is live on the production server BUT no problems when doing it in the development environment-very weird.
Browser Console
IIS Normal Logs
IIS Failed Request Tracing on 500
I had similar problem 2 weeks ago and also had posted about it in stackoverflow [asp.net web api: only during sql connection - HTTP 500 Error occurs : Local host is currently unable to handle request.
After hours of looking into the issue, it was figured out as a stored procedure missing in database.
Not sure whether it will help you with the problem, but hope it can give you some lead to resolve the problem.
Following #A.Roussos's advice to use Visual Studio debugging on the PRODUCTION SERVER (might seem obvious for me it wan't haha), I got some information.
My problem is that before I save data to the database I parse a string to double using the parse function.
Example
double a = Double.Parse(mystring);
The problem however is apparently the parse function is reliant on your regional settings(CultureInfo).
So I just added the following information to the code
double a = Double.Parse(mystring,System.Globalization.CultureInfo.InvariantCulture);
Something to note is that my application didn't crash when I got the 500 Internal Server Error, I didn't have a clue as to what could cause it.After using Visual Studio I got sufficient information to use and google and figure this thing out.
What killed me was that the application(or the one specific controller action in the application) worked perfectly on the development environment but not on the production environment, something like that has never happened to me and I am glad I got this learning experience.
Can you make sure that the URL which you are hitting doesn't has any whitespace in it?
Have the web.Config set to the custom errors mode as off. You should be able to see the full errors and any additional details associated with these.
Many times there are missing aspects in the environment that causes these errors.
It seems that the error is generated by a private method being called in the controller's action method but the error itself is getting eaten (empty catch) or just throw, causing an application failure. Check if the exception handler is present and logging the details somehow.
I want to redirect all url errors
The url I want to cath is ~/bla/foo
It should redirect to ~/error404.aspx
bla exists as a folder. foo does not exist.
I already set the webconfig to point to my error but I just doesn't work. I get this error:
Server Error in application /.
-------------------------------------------------- ------------------------------
The source can not be found.
Description: HTTP 404. Perhaps you are looking for the source (or a dependency thereof) removed or is temporarily unavailable or has changed its name. Check the spelling of the URL.
Requested URL: / bla/foo.asox
I google translate this error cuz VS here is language specific.
What can I do to resolve this??? I want to point to ~/error404.aspx
You can also configure a custom 404 page in IIS (this example is IIS 6). That way request for any resource that doesn't exist will go to your custom error404.aspx page.
There's also a walk through here with screen shots here if that helps. This would be something you configure outside of your application.
If you want to change the 404 message to a custom one, here are the steps to override the default one:
You can use:
protected void Application_Error(object sender, EventArgs e)
{
}
http://aspnetresources.com/articles/CustomErrorPages.aspx
There are more details in the link which show you exactly how to catch the 404 error and handle it.
I've got a page that lets you upload files. I've increased the maximum filesize to the desired level and that works but I would like to have customised error handling for when the user uploads something too big.
All the guides I've found so far give advice on how to redirect to a specal error page, I can't find anything on how to just present the error in a current page. Here's what I'm using so far.
protected override void OnError(EventArgs e)
{
HttpContext hcCurrentContext = HttpContext.Current;
Exception eException = this.Server.GetLastError();
if (eException.Message.Equals("Maximum request length exceeded."))
{
hcCurrentContext.Server.ClearError();
tbErrorMessage.Text = "File too large";
tbErrorMessage.Visible = true;
}
else
{
base.OnError(e);
}
}
I ran it through a debugger and it does go into the If clause correctly, but I still get redirected to the default FireFox error page with the message "The connection to the server was reset while the page was loading". Can anyone advise me?
Trapping exceptions that arise when large files are uploaded is hard, as there are inbuilt checks in IIS to prevent denial-of-service attacks that cause these exceptions to be generated.
See Jon Galloway's post for details on how to get around this. In essence you'll need to
Attempt reconfiguration of IIS to handle larger files
Try an third-party component that allows larger files
Trap HTTP 400 in IIS - which isn't ideal, as the 400 code can happen in other circumstances.