本篇来讲讲对web.config文件的读写,并不是谁都可以对web.config文件进行读写操作的,必须要有一定的权限才行的。
      其实在web.config中的很多的配置节点都是与一个类相对应的,我们可以通过相应的类来,利用其强类型的API来对相应的配置进行访问,而不用把web.config 当做一个XML来读取。
      我们可以用两种方式来对配置文件进行访问,首先,可以用强类型的API来访问,这就要用要ConfigurationManager类。如下:

using System.Web.Configuration;
using System.Configuration;
 
protected void Page_Load(object sender, EventArgs e)
{
    SessionStateSection sts 
=(SessionStateSection)ConfigurationManager.GetSection("system.web/sessionState");
    Response.Write(
"The session state mode is: " + sts.Mode.ToString() + "<br/>");
}

相关文章:

  • 2021-12-08
  • 2021-12-30
  • 2021-11-02
  • 2021-11-05
  • 2021-11-22
  • 2022-01-01
  • 2018-05-22
  • 2021-11-01
猜你喜欢
  • 2021-05-23
  • 2021-12-15
  • 2017-12-08
  • 2021-12-18
  • 2021-12-20
  • 2021-11-04
  • 2021-09-27
  • 2019-06-02
相关资源
相似解决方案