Solution to the problem of the Web basic class (Inheriting System. Web. UI. Page ~

Source: Internet
Author: User

I believe that many people will build a project that inherits fromThe system. Web. UI. Page class adds a lot of public partsCodePut it into it, such as permission detection and error handling (convenient). However, when constructing such a class, there is a problem that requires special attention, that is, the attribute definition of the class, let's take a look at the following attributes:

Public Hashtable extends tsecuritychecker

{

Set

{

Application ["AA"]=Value;

}

Get

{

If (Application ["AA"] =   Null )

{< br>
application [" AA "] = New hashtable ();

}

 

Try

{< br> return (hashtable) application [" AA "];

}

Catch

{

Application ["AA"] =   New Hashtable ();

Return (Hashtable) application ["AA"];

}

}

}

 

At first glance, it seems that there is no problem. Even the error handling is completed, and the compilation can also be successful. However, the basic page class is an interface class. What is the problem? After the interface class is inherited, its attributes will be initialized by the quilt class. When our subclass inherits this class, its own

WebThe editing interface cannot be opened again (depressed~), So if you want to use a similar function, you can modify it like this.

Private Hashtable _ javastsecuritychecker =   Null ;

Public Hashtable geteffectchecker ()

{

If (Application ["AA"] =   Null )

{

Application ["AA"]= NewHashtable ();

}

Try

{

Return(Hashtable) application ["AA"];

}

Catch

{

Application ["AA"]= NewHashtable ();

Return(Hashtable) application ["AA"];

}

}

All subclasses passGeteffectchecker ()Method, because the method does not affect interface initializationWebThe interface can still be edited normally.

 

One thing to emphasize is that the first approach will not affectProgram.

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.