1
我想寫一個具有兩個其他角色提供程序的自定義角色提供程序。我寫了一個自定義的成員資格提供這樣的:如何從web.config獲得RoleProvider
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;
}
}
我無法找到任何方法得到,請幫助我,謝謝。
你嘗試System.Web.Security.Roles.Providers財產?它返回RoleProviderCollection,這是ASP.NET應用程序的角色提供程序的集合。 – SBirthare