不带连接字符串的.Net RoleProvider

发布于 2024-08-19 08:51:46 字数 734 浏览 7 评论 0 原文

我想在我的应用程序中使用.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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清引 2024-08-26 08:51:46

我遇到了 此页面,建议“下载ProviderToolkitSamples 并修改 SQLConnectionHelper 类。具体来说,GetConnectionString 函数看起来像这样“

internal static string GetConnectionString(string specifiedConnectionString, bool lookupConnectionString, bool appLevel)
{
        if (specifiedConnectionString == null || specifiedConnectionString.Length < 1)
            return null;

        string connectionString = null;

        /////////////////////////////////////////
        // Step 1: Check <connectionStrings> config section for this connection string
        if (lookupConnectionString)
        {
            ConnectionStringSettings connObj = ConfigurationManager.ConnectionStrings[specifiedConnectionString];
            if (connObj != null)
                connectionString = connObj.ConnectionString;

            if (connectionString == null)
                return null;
        }
        else
        {
            connectionString = specifiedConnectionString;
        }

        return connectionString;
    }
}

文本摘自 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"

internal static string GetConnectionString(string specifiedConnectionString, bool lookupConnectionString, bool appLevel)
{
        if (specifiedConnectionString == null || specifiedConnectionString.Length < 1)
            return null;

        string connectionString = null;

        /////////////////////////////////////////
        // Step 1: Check <connectionStrings> config section for this connection string
        if (lookupConnectionString)
        {
            ConnectionStringSettings connObj = ConfigurationManager.ConnectionStrings[specifiedConnectionString];
            if (connObj != null)
                connectionString = connObj.ConnectionString;

            if (connectionString == null)
                return null;
        }
        else
        {
            connectionString = specifiedConnectionString;
        }

        return connectionString;
    }
}

Text lifted from williablog.net, since as that page says, "links have a way of breaking over time"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文