Asp. Net custom Section Handler

Source: Internet
Author: User

1. Asp. Net Configuration

Web. config contains various configurations of Asp. Net programs. Web. config contains two parts: Section Handler and Section Settings. You may want to say that the web. config contains the appsettings and connectionStrings which do not belong to these two parts. Otherwise, you can easily view the machine. config.

<ConfigSections>
<Section name = "etettings" type = "System. configuration. appSettingsSection, System. configuration, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a "restartOnExternalChanges =" false "requirePermission =" false "/>
<Section name = "connectionStrings" type = "System. Configuration. ConnectionStringsSection, System. Configuration, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a" requirePermission = "false"/>
...

It can be seen that the appSettings and connectionStrings in web. config are actually the settings of these two sections.

Ii. Custom Configuration

In such a scenario, the system should provide user friendly prompts, for example, hello. It is very appropriate for Chinese users, but not for English users. Therefore, we can design it as follows:

Public interface IHelloGenerator
{
String GenerateHello ();
}
Public class CnHelloGenerator: IHelloGenerator
{
# Region IHelloGenerator Members

Public string GenerateHello ()
{
Return "hello ";
}

# Endregion
}
Public class EnHelloGenerator: IHelloGenerator
{
# Region IHelloGenerator Members

Public string GenerateHello ()
{
Return "Hello ";
}

# Endregion
}
Define an interface to generate a greeting, and define a class to implement this interface for different languages to generate a specific greeting. In use, you can:

Class App
{
Static void Main ()
{
Var helloGenerator = CreateHelloGenerator ("cn ");

Console. WriteLine (helloGenerator. GenerateHello ());
}

Private static IHelloGenerator CreateHelloGenerator (string lang)
{
Var result = default (IHelloGenerator );
Switch (lang)
{
Case "en ":
Return new EnHelloGenerator ();
Case "cn ":
Return new CnHelloGenerator ();
}

Return result;
}
}

  • Three pages in total:
  • Previous Page
  • 1
  • 2
  • 3
  • Next 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.