Save the data in the web. config configuration file, and how to obtain the data in the config configuration file, web. configconfig

Source: Internet
Author: User
Tags connectionstrings

Save the data in the web. config configuration file, and how to obtain the data in the config configuration file, web. configconfig

<1>

Some data needs to be written to the configuration file. We should try to write it into the configuration file. For example, you can change the frequently changed data or change the configuration file to use a value, such as an IP address. Port Number, MD5 and salt. And so on. We can write these values into the web. config file. You can obtain this value on the webForm. aspx. cs page or other pages.

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

<? Xml version = "1.0" encoding = "UTF-8"?> <! -- Access the http://go.microsoft.com/fwlink/ for detailed messages about how to configure ASP. NET applications? 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 should try to write it into the configuration file. For example, you can change the frequently changed data or change the configuration file to use a value, such as an IP address. Port Number, MD5 and salt. And so on. We can write these values into the web. config file. In webForm. aspx. cs page, or you can get this value from other pages --> <appSettings> <add key = "IP" value = "192.168.1.199"/> <add key = "port number" value = "8080 "/> <add key =" MD5 salt adding "value =" my salt "/> </appSettings> </configuration>

Obtain from the webForm. aspx. cs File

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. deleetask[ "IP"]; string duankouhao = ConfigurationManager. appSettings ["port number"]; string mySalt = ConfigurationManager. appSettings ["MD5 salt adding"] ;}}


static readonly string smtpServer = System.Configuration.ConfigurationManager.AppSettings["SmtpServer"];        static readonly string userName = System.Configuration.ConfigurationManager.AppSettings["UserName"];        static readonly string pwd = System.Configuration.ConfigurationManager.AppSettings["Pwd"];        static readonly int smtpPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpPort"]);        static readonly string authorName = System.Configuration.ConfigurationManager.AppSettings["AuthorName"];        static readonly string to = System.Configuration.ConfigurationManager.AppSettings["To"];


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.