Error handling support in ASP.NET

xiaoxiao2021-03-06  27

Http://www.it918.com/htm/jc/jcwlbc/asp.net/20040427c095124. Error handling support in SHTMLASP.NET

Www.it918.com Green Apple Studio 2004-4-27 [Reprint Please indicate the source]

[

I will say two sentences] [

Hardware product offer] [

I want "" wrong] [font:

Big

in

small 】【

Print]

shut down 】

A.XWGJZ: LINK {Color: # 0c00ad; font-size: 14px; text-decoration: underline}

A.XWGJZ: Visited {color: # 0c00ad; font-size: 14px; text-decoration: underline}

A.XWGJZ: Active {Color: # 0c00ad; font-size: 14px; text-decoration: underline}

A.XWGJZ: Hover {color: # ff0000; font-size: 14px; text-decoration: underline}

a.xwgjz: link {

TEXT-DECORATION: underline;

COLOR: # 3366cc;

FONT-SIZE: 14PX;

Font-Family: Arial, Helvetica, Sans-Serif

}

a.xwgjz: visited {

TEXT-DECORATION: underline;

COLOR: # 3366cc;

FONT-SIZE: 14PX;

Font-Family: Arial, Helvetica, Sans-Serif

}

a.xwgjz: hover {

TEXT-DECORATION: underline;

Color: # ff4400;

FONT-SIZE: 14PX;

Font-Family: Arial, Helvetica, Sans-Serif

}

a.xwgjz: Active {

TEXT-DECORATION: underline;

COLOR: # 3366cc;

FONT-SIZE: 14PX;

Font-Family: Arial, Helvetica, Sans-Serif

}

A.Red:LINK {

TEXT-DECORATION: underline;

COLOR: # 3366cc;

FONT-SIZE: 14PX;

Font-Family: Arial, Helvetica, Sans-Serif

}

A.red:visited {

TEXT-DECORATION: underline;

COLOR: # 3366cc;

FONT-SIZE: 14PX;

Font-Family: Arial, Helvetica, Sans-Serif

}

A.Red :hover {

TEXT-DECORATION: underline;

Color: # ff4400;

FONT-SIZE: 14PX;

Font-Family: Arial, Helvetica, Sans-Serif

}

A.Red:Active {

TEXT-DECORATION: underline;

COLOR: # 3366cc;

FONT-SIZE: 14PX;

Font-Family: Arial, Helvetica, Sans-Serif

}

a.next:link {

Text-decoration: none;

COLOR: # 3366cc;

FONT-SIZE: 14PX;

Font-family:;

}

a.next:visited {

Text-decoration: none;

COLOR: # 3366cc;

FONT-SIZE: 14PX;

Font-family:;

}

a.next:Hover {

Text-Decoration: underline; color: # ff4400;

FONT-SIZE: 14PX;

Font-family:;

}

a.next:Active {

Text-decoration: none;

COLOR: # 3366cc;

FONT-SIZE: 14PX;

Font-family:;

}

.red {

Color: # ff0000;

Font-family:;

}

.bou {

COLOR: # 3366cc;

Font-family:;

Font-weight: bold;

}

A.xgwz: Active {

FONT-SIZE: 14PX;

Color: # 1648be;

Text-decoration: none;

Line-height: 22px;

}

a.xgwz: link {

FONT-SIZE: 14PX;

Color: # 1648be;

Text-decoration: none;

Line-height: 22px;

}

a.xgwz: visited {

FONT-SIZE: 14PX;

Color: # 1648be;

Text-decoration: none;

Line-height: 22px;

}

A.xgwz: hover {

FONT-SIZE: 14PX;

Color: # ff9900;

TEXT-DECORATION: underline;

Line-height: 22px;

}

.spanclass {visPanclass; width: 760px; height: 1px; position: absolute; left: 1px; top: 1px}

Website Promotion: Shopping Information Revolution - Price Network

Sunshine online best small game

ASP.NET has a good new feature: it provides rich support for the processing and tracking of runtime errors. In particular, it provides managers with a very simple way to ensure the fear of "ASP 43433AX" sixteen-based errors will never be displayed in front of our customers. Instead, it allows a more customized information, such as "Sorry, this site is not available". ASP.NET also provides a powerful way to enable developers to equip their code to provide managers with additional information and notices that occur in work site problems. This article details these two technologies, while the end includes a sample code, you can use it directly.

Ensure that security information will not be blocked

ASP.NET is the same as previous ASP, and an HTML error page is generated when a run time or compiling time error occurs on the server. But unlike ASP, ASP.NET is particularly concerned: to ensure that "security" information will be leaked by this error in the default state. Especially if you click on the server from a remote machine. The "Out of the Box" type error handling setting will not cause compiler information of the remote machine, leak configuration information, file name, stack record, source code, or linear data. Conversely, remote users will only see a general information such as "Application Error". To view the wrong details, users must: 1) Click on the page again from the local server, or 2) Modify the configuration settings in the machine or application's config.Web file to allow remote access:

We hope that by setting the default status to we have to "safe", we can ultimately help protect the integrity and security of the application. And thereby correcting many ASP developers - especially ASP managers are reflected in a common complaint / worry).

Use custom error pages

Although the public error message we sent to the user is safe, it does not threaten the secret of the application, but such information is not good. Maybe you want users to never see such information. Conversely, when a request is processed, if an error occurs, you want to display your own "custom error page", show your brand and specific error messages. Adding a custom error message to the ASP.NET application is very easy. First, write your own web page, which can be any type of file: .htm, .aspx, .asp, and so on. The configuration information is then modified in the application's config.Web file to let it point to this file. For example, the following configuration information describes that the browser should be redirected to the "ERRORPAGE.ASPX" page when any failed predetermined error has occurred:

The "DefaultInderct" attribute in the tag defines the "default" page that the user will be redirected in the case where an error occurs. Alternatively, you can redirect this default value according to the response HTTP code status. For example: redirect to a special "File" error page, "Illegal Access" error page, "Server Conflict" error page, etc. For example, the following configuration information covers 3 specific HTTP status code, all other errors returns to a default page:

One thing we have encountered on custom error pages, that is, although they are very useful for the completed situation, but it is very difficult to deal with during development. Because you are expected to have bugs during the development process, and when you find it, I really want to see the actual error message tracking. To solve this problem,

The tag supports a "mode" property with 3 values: "ON": It always makes a custom error page; "OFF": means never issuing a custom error page (you always see the original error message); "Remoteonly": It means that only custom error pages only when the remote browser click on the site (and the developer who click on the site on the actual machine sees detailed error message).

Equipment application helps administrator tracking errors

Although the custom error message is a good thing, maybe you still hope that when an error occurs on the site, developers and administrators can easily find it in real time, and identify what problems, URLs and What is the exception information? To solve this problem, ASP.NET introduces a new "application layer" event that can be processed in the global.asax file: "Application_ERROR". During processing a web request, this method is called when there is an unprocessed exception. Developers can obtain special information about the request, such as the URL of the page, query string variable, user agent, cookie's value, etc., and information of the actual exception object of package error message. Then you can continue, run any of what they want to track and to notify the administrator and developers, which may include using System.Diagnostic Apis to write information to NET event log, using System.Web.util SMTP Email APIs send Email to the administrator, write information to a database, and so on. For example, the following Global.asax file demonstrates how to write an error message to a custom NT event log "MyCustomLog", including page URL and exceptional stack record: <% @ Import namespace = "system.diagnostics"%>