c# - ASP.NET中从connectionStrings中动态读取configSource的值

标签 c# asp.net connection-string configsource

<分区>

我在开发过程中根据需要手动更改 configSource 以指向本地 SQL Server 或 SQL Azure 服务器。我希望我的代码找出 configSource 的值,以便我的代码知道正在使用哪个数据库服务器。

使用 C#,如何获取当前的 configSource 值?

请注意,这与获取 Windows 应用程序的 configSource 不同!这种方式在 ASP.NET 中不起作用!

最佳答案

以下代码将从 web.config 中读取 connectionStrings 的配置部分,并获取 ConfigSource 属性:

ConnectionStringsSection connectionStringsSection = 
      System.Web.Configuration.WebConfigurationManager
     .GetSection("connectionStrings", "/Web.config") as ConnectionStringsSection;
string configSource = connectionStringsSection.SectionInformation.ConfigSource;

关于c# - ASP.NET中从connectionStrings中动态读取configSource的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25983327/

相关文章:

C# listview 最佳列宽

c# - 调用长时间运行的方法并继续执行其他任务

c# - SharePoint 中的 FBA 登录页面问题

c# - 存储过程的返回值仅在 ASP.NET 中获取第一个字符

c# - 设置一个 C# 方法,在第一次失败后尝试重新连接到不同端口上的 SQL Server

.net - 加密 connectionStrings 部分 - app.config 的实用程序

javascript - 使用不同的二进制数查找给定集合的子集

c# - 如何处理多语言界面?

javascript - 在 asp.net 中自动调整面板中子控件的大小

connection-string - xUnit 测试项目连接字符串