Custom exception classes in ASP. NET forums

Source: Internet
Author: User
Original article: http://blog.joycode.com/dotey/archive/2005/01/20/43363.aspx

Custom exception classes in ASP. NET forums

Forums has a custom exception class forumexception, which inherits from applicationexception and corresponds to an enumeration forumexceptiontype to record the exception type. Forums custom exception classes are mainly used to handle various possible exceptions separately --Record error logs,Message prompt.

When an exception is thrown in Asp.net, the error event of httpapplication is triggered and can be captured in httpmodule. For example, forums is used to handle the forums exception in its httpmodule: application. error + = new eventhandler (this. application_onerror );. After a custom exception is caught, logs of important error messages are recorded (saved to the forums_exceptions table of the database) based on the exception type (forumexceptiontype enumeration) for the Administrator's reference. For exceptions, a friendly error message is displayed based on the exception class to give user-friendly prompts.

Forums custom exceptions not only serve to handle error exceptions, but also serve as information prompts. For example, if a user registration is successful, an exception is thrown: throw new forumexception (forumexceptiontype. useraccountcreatedauto); then, the system automatically jumps to the prompt that the user has successfully registered.

How does forums jump to the corresponding information based on exceptions? As mentioned above, forums has an error type enumeration for each custom exception. forums has a messages. XML for each language. The XML rules are as follows:

  <  Root  >    <  Message  ID  = "1"  >    <  Title  >  No permission to log on  </  Title >    <  Body  >  You are not a super administrator.  </  Body  >    </  Message  >    <  Message  ID  = "2" >    <  Title  >  No permission to modify  </  Title  >    <  Body  >  This forum does not exist, or you are not authorized to modify it.  </  Body  >   </  Message  >    </  Root  > 

The IDS correspond to the int type of forumexceptiontype one by one.

  Public     Enum  Forumexceptiontype ...  {Administrationaccessdenied= 1, Posteditaccessdenied= 2,} 

When an exception is handled in the httpmodule, the response page will jump directly to the Message prompt page. redirect (globals. getsiteurls (). message (exception. exceptiontype), true); such as http: // localhost/cnforums/msgs/default. aspx? Messageid = 1 on the MSG display page, the corresponding prompt information is found from the XML according to the messageid, and displayed on the page.

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.