Reading value from web.config file?

别说谁变了你拦得住时间么 提交于 2020-01-17 02:27:11

问题


From my DAL, How can i read a connection string from the web.config?


回答1:


You can use the WebConfigurationManager to read connection string value from web.config

Code Example:

using System.Configuration;

string connString = WebConfigurationManager.ConnectionStrings["ConnectionString"].ToString();

Make sure you have added the System.configuration reference to your DAL.




回答2:


using System.Configuration;

static string connectionString = 
    ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;

Yuu only need WebConfigurationManager if there are several Web.Config files in your project using data connection strings:

What's the difference between the WebConfigurationManager and the ConfigurationManager?




回答3:


System.Configuration.ConfigurationManager.ConnectionStrings["connStr"].ConnectionString


来源:https://stackoverflow.com/questions/13029873/reading-value-from-web-config-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!