In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "ASP.NET how to configure file Web.config". In daily operation, I believe many people have doubts about how ASP.NET configures file Web.config. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts of "ASP.NET how to configure file Web.config"! Next, please follow the editor to study!
The Web.config file is an XML text file that stores configuration information for ASP.NET Web applications (such as the most common way to set the authentication of ASP.NET Web applications), and it can appear in every directory of the application. When you create a new Web application through VB.NET, a default Web.config file is automatically created in the root directory by default, including the default configuration settings, and all subdirectories inherit its configuration settings. If you want to modify the configuration settings of the subdirectory, you can create a new Web.config file in that subdirectory. It can provide configuration information in addition to the configuration information inherited from the parent directory, or it can override or modify settings defined in the parent directory.
Changes to the Web.config file at run time do not need to restart the service to take effect (note: section exception). Of course, Web.config files can be extended. You can customize the new configuration parameters and write configuration section handlers to handle them.
I. web.config configuration file (default configuration settings)
All of the following code should be located in
And
The following example omits this XML tag for learning purposes
1. Section
Function: configure ASP.NET authentication support (for Windows, Forms, PassPort, None). This element can only be declared at the computer, site, or application level. Element must be used in conjunction with a section.
Example:
The following example configures the site for form-based (Forms) authentication. When a user who does not log in visits a page that requires authentication, the page automatically jumps to the landing page.
The element loginUrl represents the name of the landing page, and name represents the name of the Cookie.
2. Section
Purpose: to control client access to URL resources (such as allowing anonymous users to access). This element can be declared at any level (computer, site, application, subdirectory, or page). Must be used in conjunction with the section.
Example: the following example disables access to anonymous users
Note: you can use user.identity.name to get the current authenticated user name; you can use the web.Security.FormsAuthentication.RedirectFromLoginPage method to redirect the authenticated user to the page that the user has just requested.
3. Section
Purpose: configure all compilation settings used by ASP.NET. The default debug property is "True". After the program has been compiled and delivered, it should be set to True (as detailed in the Web.config file, examples are omitted here)
4 、
Purpose: to provide ASP.NET applications with information about custom error messages. It does not apply to errors that occur in XML Web services.
Example: when an error occurs, jump the page to a custom error page.
Where the element 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.
5. Section
Purpose: configure ASP.NET HTTP runtime settings. This section can be declared at the computer, site, application, and subdirectory levels.
Example: control users to upload files * is 4m, the maximum time is 60 seconds, and the maximum number of requests is 100
6 、
Purpose: identifies page-specific configuration settings (such as whether session state is enabled, view state, whether to detect user input, and so on). Can be declared at the computer, site, application, and subdirectory levels.
Example: does not detect whether the user has potentially dangerous data in the browser input (Note: this default is detection, if you use non-detection, one is to encode or verify the user's input). When sending back the page from the client, the encrypted view state is checked to verify that the view state has been tampered with on the client side. (note: this item is not verified by default)
7 、
Purpose: configure session state settings for the current application (such as setting whether session state is enabled, where session state is saved).
Example:
Note:
Mode= "InProc" says: save session state locally (you can also choose to store it on a remote server or SAL server or not enable session state)
Cookieless= "true" indicates that session state is enabled if the user's browser does not support Cookie (default is False)
Timeout= "20" indicates the number of minutes a session can be idle
8 、
Function: configure ASP.NET tracking service, which is mainly used for program testing to determine what went wrong.
Example: the following is the default configuration in Web.config:
Note:
Enabled= "false" indicates that tracing is not enabled; requestLimit= "10" indicates the number of trace requests stored on the server
PageOutput= "false" means that trace output can only be accessed through the trace utility
TraceMode= "SortByTime" means to display trace information in the order in which it is processed.
LocalOnly= "true" means that the trace viewer (trace.axd) is only used to host the Web server
Custom Web.config file configuration section
The process of customizing the Web.config file configuration section is divided into two steps.
One is to declare the name of the configuration section and the name of the .NET Framework class that handles the configuration data in that section between the top of the configuration file and the tag.
The second is to make the actual configuration settings for the declared section after the area.
Example: create a section storage database connection string
.
Access to Web.config files
You can access the Web.config file example by using the ConfigurationSettings.AppSettings static string collection: get the connection string established in the above example.
Create a Web.config file
1. In solution Explorer, click the Refresh icon to confirm that the application does not have an Web.config file.
If you have used the Web site Administration tool or some other way to configure your application, you may have automatically created the Web.config file. Click Refresh to update the list of files.
two。 In solution Explorer, right-click the site name, and then click add New item.
3. In the templates window, click Web profile.
The file name in the name text box should be Web.config. You can provide a different name for the file, but this is the default name. The .config file extension prevents ASP.NET from downloading the file.
4. Click add to create the file, and then open it for editing.
This file contains the code shown in the examples section later in this topic and has some initial defaults. The application inherits all configuration settings from the Machine.config and Web.config files in the% SystemRoot%\ Microsoft.NET\ Framework\\ CONFIG directory, but you can't see these default settings here. If you want to override inherited default settings or add collection elements such as httpHandlers elements (ASP.NET settings schema), you only need to create application-level and directory-level Web.config files.
To view all configuration settings for the current application, you can run the topic how to: programmatically view the code contained in inherited and local configuration settings. You can also view the Machine.config.comments or Web.config.comments files (which also contain useful comments) in the% SystemRoot%\ Microsoft.NET\ Framework\\ CONFIG directory, but these two files will not contain all runtime settings, see how to: view inherited and local configuration settings programmatically.
5. If you make changes to the Web.config file, save it.
Saving the Web.config file restarts the application. You can also choose to use the configSource attribute of a single section element to point to a secondary profile, and changing the secondary profile does not cause the application to restart. For more information, see configSource in the general attributes inherited by the section element.
Web.config is a very important configuration file in asp.net applications. Through the Web.config file, it is convenient for us to develop and deploy asp.net applications.
At this point, the study on "how to configure the file Web.config for ASP.NET" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.