1

我想编写一个自定义角色提供者,它有两个其他角色提供者。我写了一个这样的自定义会员提供程序:

public class CustomMemberProvider : MembershipProvider
{
    MembershipProvider _sqlProvider = null;
    MembershipProvider sqlProvider
    {
        get
        {
            if (_sqlProvider == null)
                _sqlProvider = System.Web.Security.Membership.Providers["SqlProvider"] as SqlMembershipProvider;
            return _sqlProvider;
        }

    }
    MembershipProvider _adProvider = null;
    MembershipProvider adProvider
    {
        get
        {
            if (_adProvider == null)
                _adProvider = System.Web.Security.Membership.Providers["AdProvider"] as MembershipProvider;
            return _adProvider;
        }

    }
    ....

现在,我也想从 web.config 中获取这两个角色提供者,如下所示:

public class CustomRoleProvider : RoleProvider
{
    private static readonly string m_RoleProviderNamePrefix = System.Web.Configuration.WebConfigurationManager.AppSettings["RoleProviderName"] + ":";

    RoleProvider _sqlProvider = null;
    RoleProvider sqlProvider
    {
        get
        {
            if (_sqlProvider == null)
                _sqlProvider = ??????
            return _sqlProvider;
        }

    }
    RoleProvider _adProvider = null;
    RoleProvider adProvider
    {
        get
        {
            if (_adProvider == null)
                _adProvider = ??????
            return _adProvider;
        }

    }

我找不到任何方法来获得它,请帮助我,谢谢。

4

1 回答 1

0

您可以通过 web.config 的内置部分插入您的提供程序。它们不需要相互引用,它们只需要实现提供者期望的正确功能。

成员资格提供程序示例:http: //msdn.microsoft.com/en-us/library/6e9y4s5t%28v=vs.100%29.aspx

角色提供者(标签)示例:http: //msdn.microsoft.com/en-us/library/tksy7hd7%28v=vs.100%29.aspx

于 2013-08-19T06:05:03.007 回答