我想在我的应用程序中使用.Net 的 SqlMembershipProvider 和 SqlRoleProvider 进行用户管理。我的问题是,当应用程序启动时,它不知道任何数据库连接信息。出于安全目的,它需要从数据库服务器上运行的 WCF 服务获取此信息。因此,我需要事后建立我的会员/角色提供者。
我想我已经能够创建和添加成员资格提供程序:
// register membership provider
var membership = new SqlMembershipProvider();
var providerValues = new NameValueCollection();
providerValues.Add("name", "sqlMembershipProvider");
providerValues.Add("applicationName", "/");
providerValues.Add("connectionStringName", "connectionStrDynamAddedToConfig");
providerValues.Add("maxInvalidPasswordAttempts", "10");
membership.Initialize("sqlMembershipProvider", providerValues);
到目前为止,我无法找到类似的方法来创建 RoleProvider。我可以创建提供程序,但无法将其添加到角色管理器中。我是否需要创建一个可以在初始化后获取连接字符串的自定义提供程序?
I would like to use .Net's SqlMembershipProvider and SqlRoleProvider for user management in my application. My issue is that when the application starts, it does not know any db connection information. For security purposes, it needs to get this information from a WCF service that is running on the datbase server. Therefore I need to build my membership/role providers after-the-fact.
I think I've been able to work out creating and adding the membership provider:
// register membership provider
var membership = new SqlMembershipProvider();
var providerValues = new NameValueCollection();
providerValues.Add("name", "sqlMembershipProvider");
providerValues.Add("applicationName", "/");
providerValues.Add("connectionStringName", "connectionStrDynamAddedToConfig");
providerValues.Add("maxInvalidPasswordAttempts", "10");
membership.Initialize("sqlMembershipProvider", providerValues);
I have, so far, been unable to work out something similar to create the RoleProvider. I can create the provider, but cannot add it to the Roles Manager. Do I need to create a custom provider that can take a connectionString after it is already initialized?
发布评论
评论(1)
我遇到了 此页面,建议“下载ProviderToolkitSamples 并修改 SQLConnectionHelper 类。具体来说,GetConnectionString 函数看起来像这样“
文本摘自 williablog.net,因为正如该页面所说,“链接有一种方式。随着时间的推移而破裂”
I ran across this page, which recommends "downloading the ProviderToolkitSamples and modifying the SQLConnectionHelper Class. Specifically, the GetConnectionString function which looks something like this"
Text lifted from williablog.net, since as that page says, "links have a way of breaking over time"