Reading value from web.config file?

2019-09-07 11:01发布

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

3条回答
ゆ 、 Hurt°
2楼-- · 2019-09-07 11:03
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楼-- · 2019-09-07 11:08
System.Configuration.ConfigurationManager.ConnectionStrings["connStr"].ConnectionString
查看更多
Root(大扎)
4楼-- · 2019-09-07 11:27

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.

查看更多
登录 后发表回答