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"];