In ASP.net, a small custom error is displayed

Source: Internet
Author: User
Asp.net| Error | display
Print the error message.
public static string ShowError (Exception e)
{
Return "<font size=2> program error:" +e.message + "<BR> Details:" + e.stacktrace + </font> ";
}


public static void Checknull (object A,system.web.ui.page B)
{
if (object. Equals (A,null))
{
System.Web.UI.Page p=b;
P.response.write ("<font size=2> exception: <font color=red> Invalid ID parameter value (to find a record that matches the ID value). </font> <a href=\ "javascript:history.back (); \ > Click Back </a></font>");
P.response.end ();
}
}

More simple, no explanation ... The first is a simple error message when the program goes wrong. (It seems to be less than ha.)

The second major prevents access to records that do not exist, resulting in records. For example ... userinfo.aspx?id=12 (normal)

But userinfo.aspx?id=1245821521 made a mistake.

Call this on the code page:

Cp_user User=usermanager.getuser (Convert.toint64 (_id));
Secu.Str.CheckNull (User,this); This sentence ~! ~! ~! ~! ~! ~!

Username.text=user.uname;

If the GetUser method returns a valid object, it is skipped directly after the check.
If the record does not exist at all, it returns a null ... Displays an error and stops the execution 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.