Display Error Stack trace information in Custom Error page - c#

I am using VS2010.
I log my exception in Application_Error and then get automatically redirected to Custom Error page.
On Custom Error page, I would like to display stack track of the error.
I can not implement the approach in following article because I am
using ajax controls in all the pages and I get ajax errors if I use
the solution in following article.
I updated the web.config as follows:
<customErrors defaultRedirect="~/CustomError.aspx" mode="On" redirectMode="ResponseRewrite" />
The ajax error for the web.config is as follows:
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near '
ASP.NET custom error page - Server.GetLastError() is null
I can not use the following approach because I am being told to stay
away from session and application level storage.
Asp.net 4.0 : How to get exception details in custom error page?
So what are my options?? is there any other way to store Error information in Application_Error and recover the error stack trace on Custom Error page? This page is automatically being rerouted by asp.net engine.

Related

Why deleting the Anti-forgery cookie manually in the browser and posting gives a 404 (.net core 2.0Razor pages)

I am assuming that this is the normal behavior...
When i go to the application tab in chrome developer tools, select and delete the anti-forgery cookie i get a default page not found 404 error.
This is a razor pages web app.
What happens after i perform a post all the way to returning a 404?
Shouldn’t it throw a missing anti forgery exception?
If it is returning a 404, why is it not returning my custom 404 page?
I have tried to create a custom exception middleware and an exception filter but can't catch this exception anywhere.
If instead of deleting the cookie if I manually modify it (chrome's developer tools Application tab) I get a 500 error... Same thing here, can't catch any exception.
Any help is welcome.
Image of the 404 error
Image of 500 error
Antiforgery token is required for all POST request made to a razor page. You can disable it globally or for a specific razor page.
For a detailed explanation check the following page:
https://www.learnrazorpages.com/security/request-verification

Why does the 404 page not work in certain cases? (IIS, Classic ASP)

Explanation
In production and locally, the 404 page for my site works fine for the most part. A URL such as http://localhost:43424/gibberish_r3hjjnwef will return the well designed 404 HTML page that is in the website folder, and pointed to by IIS.
However when I change the this URL to http://localhost:43424/gibberish_r3hjjnwef... it gives the following "hard" error, whilst still claiming to be a 404.
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /gibberish_r3hjjnwef...
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.2110.0
I'd rather it still gave the 404 HTML page.
I thought maybe it was an outright invalid URL, but both http://www.bbc.co.uk/news/fdisdhfdu and http://www.bbc.co.uk/news/fdisdhfdu... give the BBC's nice 404 page.
Question
Is there anything I can do to improve this?
Relevant Information (happy to provide more if necessary)
Microsoft .NET Framework Version: 4.0.30319
ASP.NET Version: 4.7.2110.0
Language/Framework:C#/Classic .ASP
I'm not sure whether this is what you are referring to, but maybe try this out:
Go to IIS Manager -> Site -> IIS Error pages. On the right hand panel, there's a setting "Edit Feature Settings...".
The options there mean:
Custom error pages: Use the 'IIS error pages' as fallback for all failed requests (e.g. your 404 page set up the list behind)
Detailed error pages: In case of an Asp.Net error, shows the 'Asp.Net error page' ("Server Error in '/' Application." etc.)
Detailed errors for local requests etc.: Show the 'IIS error page' for remote requests, for local requests show the 'Asp.net error page' ("Server error in '/' etc.)
This is in place to effectively hide the detailed Asp.net error page (with the stack trace etc.) from external callers as you may not want to give them the details of your application. This is the default setting, where you should only see the 'Asp.net error page' when you call the invalid URL on 'localhost', but the 'IIS error page' (404) when you call the page from a different computer.
So, what you may want to try is to select the "Custom error pages" option ('IIS error pages' for all failed requests).

CustomError and ConnectionStrings

I have an Error.aspx page to handle any Application_Error.
But there is one that I can't catch : When the site can't connect to the DB specified with the connectionstrings, Application_Error is called (in global.asax) but I don't reach Error.aspx even if there is no DB connection needed to display it. Instead, I have the standard ASP red message saying that there was an application Error on custom error page.
Any Idea to catch this error type ?

global exception handling with nlog

Is there a way blog can capture all exception without specifying a try catch? For example going to a page that is not available on a MVC website and picking up an error in Icontroller and capturing page not found. ?
NLog does not capture errors in your application. It allows you to log captured errors.
See Exception Handling in ASP.NET MVC or Global Error Handling in ASP.NET MVC to understand how you can capture errors. After exception is captured, you can log it with:
Logger.ErrorException(message, exception);

Sitefinity A potentially dangerous Request.Path value was detected from the client (?)

I am using Sitefinity 5.1 and RadGrid in this example.
I have been troubleshooting one of our pages on development server this morning and I have confirmed that it behaves differently on the page with the styling (template) than on the barebones page (no styling, no scripts etc):
The page does not work in Chrome but does work in IE and Firefox
The page on a bare-bones page (no template, header, or anything else) works in IE, Firefox and Chrome
Code used:
Response.Redirect(String.Format("~/services/separation-by-code/managesbyc?id={0}", DateTime.Now.Ticks.ToString()));
I am using ticks to refresh the page before I get there.
Here are some results:
Firefox:
seabass.ptagis.org/services/separation-by-code/managesbyc?id=634854696522350585 -> works
Chrome on the bare-bones Sitefinity page:
seabass.ptagis.org/services/separation-by-code/managesbyc?id=634854701574768045 -> works
Chrome on the styled page (CSS, Scritps, etc):
seabass.ptagis.org/services/%2fservices%2fseparation-by-code%2fmanagesbyc%3fid%3d634854699444302751 -> nope
I get the server error attached below.
I did go through all the steps of setting web.config httprequests = 2.0 and page validations = false. That did not help.
Any help is appreciated.
Server Error in '/' Application. A potentially dangerous
Request.Path value was detected from the client (?). Description: An
unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the
error and where it originated in the code. Exception Details:
System.Web.HttpException: A potentially dangerous Request.Path value
was detected from the client (?). Source Error: An unhandled
exception was generated during the execution of the current web
request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.
Stack Trace:
[HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (?).]
System.Web.HttpRequest.ValidateInputIfRequiredByConfig() +11494475
System.Web.PipelineStepManager.ValidateHelper(HttpContext context)
+184 Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
If you're using .NET 4.0, you should be able to allow the url containing a question-mark (?) via the web.config
<system.web>
<httpRuntime requestPathInvalidCharacters="<,>,*,%,&,:,\" />
</system.web>
Note, I've just removed the question-mark (?), the original default string is:
<httpRuntime requestPathInvalidCharacters="<,>,*,%,&,:,\,?" />

Categories