当前位置: 代码迷 >> ASP.NET >> Web.config文件在.aspx.cs文件中的如何读取
  详细解决方案

Web.config文件在.aspx.cs文件中的如何读取

热度:669   发布时间:2013-02-26 00:00:00.0
Web.config文件在.aspx.cs文件中的怎么读取?
web.config   文件
<configuration>
      <appSetting>
<add   key= "DSN "   value= "server=.;uid=sa;pwd=;database=pubs ">
<add   key= "SQL_products "   value= "select   *   from   Products ">
      </appSetting>
</configuration>

.aspx.cs   文件中:
string   con=ConfigurationSettings.
点时怎么点不出来的?还做什么工作吗?

------解决方案--------------------------------------------------------
在vs2005中是ConfigurationManager.Appsettins[ " "];
------解决方案--------------------------------------------------------
在VS2005里
读取Web.config建议使用专用的类
WebConfigurationManager.AppSettings[ "DSN "]

MSDN:
使用 WebConfigurationManager 是处理与 Web 应用程序有关的配置文件的首选方法;不推荐使用其他所有方法。对于客户端应用程序,建议使用 ConfigurationManager。
------解决方案--------------------------------------------------------
using System.Configuration;

string str=ConfigurationSettings.AppSettings[ " "]
  相关解决方案