开发者

Elegant Asp.Net MVC 3 custom membership wrapper class with extended (custom) methods and properties

开发者 https://www.devze.com 2023-03-05 16:19 出处:网络
I am attempting to write a custom membership class.It seems to work ok inhering the Membership class and providing functions for all the included required items (validate user, create user, delete use

I am attempting to write a custom membership class. It seems to work ok inhering the Membership class and providing functions for all the included required items (validate user, create user, delete user, isapproved, etc).

However, where I run into a problem is when I try to add properties or methods.

As all the other properties and methods are public override classes in a sealed class, the additional properties do not show up.

Say for example (example only, not "real" code):

public sealed class Membership : MembershipProvider
{
    public override string ApplicationName
    {
        get
        {
            return "myApp";
        }
    }
    public string myValue { get;set;}
}

Now, I understand why myValue will not show up when I try to do Membership.myValue but Membership.ApplicationName will.

My question is, how to exte开发者_如何转开发nd membership to show the custom items? Do I ditch Membership.xxx entirely and write a wrapper class? If so, how? I can find all the documentation in the world on how to create a custom membership class. I've got a working custom membership that works fine if I use all the available options only. I've got a custom roles provider and a custom config section to store everything and it's best friend.

What I don't have is an elegant solution.

I'd like the end result to be that I use one reference (such as Membership.xxx or myClass.xxxx) to reference all membership items + custom items.

Please provide examples of how to implement or links to appropriate items that will resolve the custom methods item.


Any time you reference the membership instance you will just have to cast it to your class type, that's all.


You can take a look at Extension Methods if you don't want to cast back and forth your instances

0

精彩评论

暂无评论...
验证码 换一张
取 消