Save data in the Web. config configuration file, and how to obtain data from the config configuration file

Source: Internet
Author: User
Tags connectionstrings

<1>

Some of the data needs to be written to the configuration file. We will try to write to the configuration file. For example, often change the data, or user time as long as the changes to the configuration file can be used value, such as: IP address. Port number, MD5 add salt. Wait a minute. We can write these values to the Web. config file. To get this value on the WebForm.aspx.cs page, or another page.

Note that the configuration is in the <appSettings></appSettings> file.

<?xml version= "1.0" encoding= "Utf-8"?><!--  For more information about how to configure an ASP. NET application, visit the  http://go.microsoft.com/ fwlink/? linkid=169433  --><configuration>    <system.web>        <compilation debug= "true" targetframework= "4.0"/>    </system.web>  <connectionStrings>    <add name= "ConnStr" connectionstring= "Data Source=fa-vaio; Initial Catalog=sales; Integrated security=true "/>     </connectionStrings><!--Some data needs to be written to the configuration file. We will try to write to the configuration file. For example, often change the data, or user time as long as the changes to the configuration file can be used value, such as: IP address. Port number, MD5 add salt. Wait a minute. We can write these values to the Web. config file. On the WebForm.aspx.cs page, or another page to get this value--  <appSettings>    <add key= "IP" value= "192.168.1.199"/ >    <add key= "port number" value= "8080"/>    <add key= "MD5 add salt" value= "my Salt"/>  </appSettings> </configuration>

WebForm.aspx.cs file to obtain the

Using system.web;using system.web.ui;using system.web.ui.webcontrols;using system.configuration;namespace user activation { Public    partial class WebForm4:System.Web.UI.Page    {        protected void Page_Load (object sender, EventArgs e)        {            string  getip= configurationmanager.appsettings["IP"];            String Duankouhao = configurationmanager.appsettings["port number"];            String mysalt = configurationmanager.appsettings["MD5 add Salt"];}}    



Save data in the Web. config configuration file, and how to obtain data from the config configuration file

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.