我想扩展静态类public static class Membership
和public abstract class MembershipProvider
有什么方法可以做到吗?
答案 0 :(得分:5)
有关如何通过继承MembershipProvider
创建自定义成员资格提供程序的完整详细说明,请参阅MSDN上的Implementing a Membership Provider。至于静态Membership
类,没有必要扩展它;你不能覆盖静态方法。它只是委托给MembershipProvider
的实例,所以你不想扩展Membership
类,你只想设置你的配置,以便调用你的新MembershipProvider。
答案 1 :(得分:0)
对于那些想要扩展现有提供商的人,例如:
using System;
using System.Web;
using System.Web.Security;
namespace System.Web.MVC_Extensions
{
public static class SqlMembershipProviderExtensions
{
public static string GenerateAccessToken(this MembershipProvider provider, string username, int expiresInMinutes)
{
if (provider.GetType().Name != "SqlMembershipProvider")
throw new NotSupportedException("Access tokens only supported by SqlMembershipProvider.");
...
}
public static bool ValidateAccessToken(this MembershipProvider provider, string username, string token)
{
if (provider.GetType().Name != "SqlMembershipProvider")
throw new NotSupportedException("Access tokens only supported by SqlMembershipProvider.");
...
}
}
}