【发布时间】:2013-02-21 16:26:44
【问题描述】:
我有一个 wbe app mvc c#4.0,我想在运行时从代码中初始化 DefaultRoleProvider 连接字符串(不希望它来自 web.config)。 我创建了一个 MyRoleProvider 类:DefaultRoleProvider
public class MyRoleProvider : DefaultRoleProvider
{
public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
{
base.Initialize(name, config);
// Update the private connection string field in the base class.
bool IsLocal = bool.Parse(ConfigurationManager.AppSettings["IsLocal"] as string);
string connectionString = "local connectionString ... ";
if (IsLocal == false)
connectionString = "prod connectionString ...";
//ToDo- how to set connection string next property of provider.
??
}
}
【问题讨论】:
-
也许您应该尝试在配置中动态设置连接字符串,然后重新加载相应的部分。见msdn.microsoft.com/query/…
-
我没有更改配置文件的权限。
标签: asp.net-mvc-4 roleprovider