Use asp.net to write Web page error information to the system log

Source: Internet
Author: User
Tags config iis system log

When designing a website, it is not possible that our website does not appear a little wrong, common "page does not exist" "Page run Error" and other error messages general website How many always exist, the key is, these errors appear, the administrator how to facilitate timely discovery of them, to minimize the user's bad impression of the site. Whether IIS 4 or IIS 5, we can set the site's "Custom error message", through this setting, some of the system defaults to the more unfriendly error messages can be replaced by the site administrator customized pages, which for the site's practical and friendly to help greatly. However, we found a more inconvenient problem in the course of use, when we looked at the site log, we found these error pages appear, but not in the system events to view these error messages. And in the log section of the site to see the error information is more cumbersome, there is no way to directly generate the error message like the security log in the system log part of it? Asp. NET can be done now. Now, let's learn how to do this in a step-by-step way.

First, the establishment of EventLog virtual directory

To implement, we build a virtual directory named "EventLog" in our website, which is as follows: In Win2000, open the "Start"-> "program"-> "Administrative Tools"-> "Internet Information Services" to find the established web site, Click "New" in the Mail, select "Virtual directory" in the pop-up menu, and then follow the wizard settings.

Ii. Modification of Web.config documents

We know that in the Web.config file, we can set the location of the error message page and the error message to display, like the "Custom error Message" page of IIS. In order to implement the functionality mentioned in this article, we need to modify the Web.config file appropriately and turn on "customErrors mode" to "on" so that the computer users can only get friendly (custom) error messages, as set out below:

<configuration>
<system.web>
<customErrors mode="On" defaultRedirect="/eventlog/customerrorpage.aspx">
<error statusCode="404" redirect="/eventlog/404Page.aspx"/>
<error statusCode="403" redirect="/eventlog/403page.aspx"/>
</customErrors>
</system.web>
</configuration>

In the above settings, we see that when the 404 and 403 errors are generated, the page will be transferred to the corresponding page we set up the EventLog virtual directory.

Iii. Establishment of other documents

To test the success of our setup, first we have to set up a page default.aspx that can generate errors, the code for this page is as follows:

Default.aspx page code

<% @Language="VB" %>
<script language="VB" runat=server>
Sub Page_Load(Sender As Object, E As EventArgs)
If IsPostBack Then
'定义变量
dim x as integer
dim y as integer
dim z as integer

x = 1
y = 0

'产生错误
z = x/y
End Sub
</script>

<body>
<form method="post" action="eventlog.aspx" name="form1" id="number">
<asp:Button id="abutton" type="submit" text="点击产生错误" runat="server" />
</form>
</body>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.