I wrote a test method on my inherited Membership Provider object a开发者_开发问答nd want to call that method by actually casting up the membership provider to my object. Membership is not of type MembershipProvider. It is the default Membership object.
((MyMembershipProvider)Membership).Test();
Thanks in advance for the help.
Sure it is possible. But if you are implementing custom membership provider, then you forgot to take property Provider
from your Membership
object. Like this:
((MyMembershipProvider)Membership.Provider).Test();
Try this:
((Membership)MyMembershipProvider).Test();
I'm guessing here, but I think your MemberShip is the class type and the MyMembershipProvider is a reference to a class (an object). You've just got your cast operands backwards.
In otherwords, you may be trying to do something like this:
int myVal = 1;
double mySecondVal = (myVal)double; // fail
double mySecondVal = (double)myVal; // success
It is possible, if the Membership
object is a MyMembershipProvider
type, and it has the .Test()
method. You can check this like that:
if (Membership is MyMembershipProvider)
(Membership as MyMembershipProvider).Test();
精彩评论