How do I call Initialize on a custom MembershipProvider?

前端 未结 8 749
死守一世寂寞
死守一世寂寞 2020-12-08 08:17

I have read through all the related questions, but I still unable to get the right solution for some reason, something is not right on my side, but not sure what\'s causing

8条回答
  •  情书的邮戳
    2020-12-08 09:07

    It's true your Initialize method should be called automatically so long as your provider is configured correctly (as it seems to be in your code sample).

    You'll need to clarify how you 'called it manually', and where you tried to cast NameValueCollection. Did it happen inside Initialize?

    Perhaps you should show us your Initialize method (you didn't forget the override keyword, did you? ;-)

    Edit: Well, the Initialize method seems fine too.

    Keep in mind: Membership is a static class, and it loads and initializes the configured providers in a lazy manner. So the construction of your provider, and the call to its Initialize method, will not occur until a call is made to either the Membership.Provider or the Membership.Providers property. Most of the other static methods (such as GetUser()) will do this, but the conclusion is that your Initialize method will not be called until the Membership API is actually used.

    Have you done this, either explicitly or by using a Login control or suchlike?

提交回复
热议问题