11.07.2015 Views

Improving Web Application Security: Threats and - CGISecurity

Improving Web Application Security: Threats and - CGISecurity

Improving Web Application Security: Threats and - CGISecurity

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

294 Part III: Building Secure <strong>Web</strong> <strong>Application</strong>sThe error page should include a suitably generic error message, possibly withadditional support details. The name of the page that generated the error is passed tothe error page through the aspxerrorpath query parameter.You can also use multiple error pages for different types of errors. For example:For individual pages you can supply an error page using the following page-levelattribute:Implement Page-Level or <strong>Application</strong>-Level Error H<strong>and</strong>lersIf you need to trap <strong>and</strong> process unh<strong>and</strong>led exceptions at the page level, create ah<strong>and</strong>ler for the Page_Error event that is similar to the one shown below.public void Page_Error(object sender,EventArgs e){// Get the source exception detailsException ex = Server.GetLastError();// Write the details to the event log for diagnostics. . .// Prevent the exception from propagating <strong>and</strong> generating an// application level event (<strong>Application</strong>.Error)Server.ClearError();}If exceptions are allowed to propagate from the page h<strong>and</strong>ler or there is no pageh<strong>and</strong>ler, an application error event is raised. To trap application-level events,implement <strong>Application</strong>_Error in Global.asax, as follows:protected void <strong>Application</strong>_Error(Object sender, EventArgs e){// Write to the event log.}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!