Asp. NET configuration Files

Source: Internet
Author: User
Tags configuration settings

Historical review:


in the computer room charging system, the use of abstract factory plus reflection to achieve database replacement function. First define The name of the assembly and the name of the namespace in the factory , and write the name and namespace values of the assembly in the configuration file. When executed to the factory function, the program automatically instantiates the corresponding object by the path by reading the corresponding character in the configuration file.

<appSettings>       
      <add key= "ConnStr" value= "Data source=192.168.24.94;initial Catalog=mycharge_sys; User Id=sa; pwd=123456 "></add>      <add key=" dbstring "value=" SQL "></add></appSettings>

This allows us not to connect to the database every time we write the connection statement, directly using reflection, and can be changed after the database directly modify the configuration file, the configuration file can be opened outside the system changes, you can use any text editing tools.


Beef Brisket Press release system, set system error automatically jumps to the error page. All error pages in the system will automatically jump to this error page.

<system.web><!--An error occurs when the auto-guided--><customerrors mode= "on" defaultredirect = "~/error.html" ></ Customerrors></system.web>

I'm understanding of the configuration file:

is created when the user logs on to the computer for the first time, and the profile is stored on the computer's local hard drive. A collection of settings and files when the user sets up and uses the software. It includes user-specific configuration settings such as program items, screen colors, network connections, printer connections, mouse settings, and window size and location.


ASP Goodbye configuration file

There are two main categories here:

1 , Machine.config

            You can have only one machine.config file, applied to all applications residing on the server. Because asp.net runtime is to load a lot of configuration files, of course Machine.config asp.net Load event, can be moved to another place, if used to load.

2 , Web. config

Each application can have a Web. config file, overriding Machine.config 's settings. Apply to a single application residing on the server

detailed Web. config

the Web. config file is an XML text file that is used to store configuration information for an ASP. NET Web application, such as the most common settings for how to authenticate the ASP. It can appear in every directory in the application. When you create a new Web application in vb.net, a default Web. config file is automatically created in the root directory, including the default configuration settings, and all subdirectories inherit its configuration settings. If you want to modify the configuration settings for a subdirectory, you can create a new Web. config file under that subdirectory. It can provide configuration information other than the configuration information inherited from the parent directory, or you can override or modify the settings defined in the parent directory.

Modifications to the Web. config file at run time do not need to restart the service to take effect. Web. config files are extensible, you can customize new configuration parameters and write configuration section handlers to process them.

Several elements:

(1) <authentication>

Role: Configure ASP. NET authentication support (for Windows, Forms, PassPort, none of the four). This element can only be declared at the machine, site, or application level. <authentication> elements must be used in conjunction with the <authorization> section.

Example: When a user without a login accesses a webpage that requires authentication, the webpage automatically jumps to the landing page.

<authentication mode= "Forms" >       

where element loginurl represents the name of the landing page, name indicates the cookie name

(2) <authorization>

Role: Controls client access to URL resources (such as allowing anonymous user access). This element can be declared at any level (computer, site, application, subdirectory, or page). Must be used in conjunction with the <authentication> section.

Example: Prohibit anonymous user access

<authorization>    <denyusers= "?" /></authorization>

? Represents an anonymous user,

       * represents all users and can also specify specific prohibitions for specific users


(3) <system.web>

<pages buffer= "true"/> all page configurations.

buffer= "true", Enable server-side buffering, the server generates a full page uniformly sent to the client .

buffer= "false" buffering is not enabled to 16K as a unit, sending to the client continuously intermittently .


<appSettings> Custom configuration of the application, general placement of constants, case-sensitive. Creates a storage database connection string.

<add key= "Con" value= "server=.; database=charge_sys;uid=sa;pwd=123456 "></add>sqlconnection con=newsqlconnection ( System.configuration.configtuationsettings.appsettings["Con"]


(4) <customErrors>

Role: Provides information about custom error messages for ASP.

Example: When an error occurs, the Web page jumps to the custom error page.

<customerrorsdefaultredirect= "errorpage.aspx" mode= "RemoteOnly" ></customErrors>

Where:DEfaultredirect represents the name of the custom error page. The mode element indicates that custom (friendly) information is displayed for users who are not running on the local Web server.

on indicates that custom error messages are visible to both local and remote users;

Off Disable custom error messages, and both local and remote users will see detailed error messages.

RemoteOnly indicates that the local user will see the detailed error message, and the remote user will see the custom error message.

Summarize:

Since there is an easy way, why go around bend? Since we can avoid duplication, we should try to achieve reusability. It can be said that the configuration file is easy to program, some of the volatile things we can pull out without the need to modify the code can be modified. Like the computer room charging system, we can change the database flexibly. The flexibility to connect to different databases. In fact, a similar function can be implemented in the way of parameters, but when the connection instance changes, the configuration file changes more easily and safely than the parameter method.




Asp. NET configuration Files

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.