How do I call Initialize on a custom MembershipProvider?

前端 未结 8 748
死守一世寂寞
死守一世寂寞 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:13

    I had a problem some time ago with this Initialize() method, I will post it here it may be helpful for someone.

    Let's imagine you have the implementation of your custom provider on:

    MyEnterprise.MyArea.MyProviders.CustomProvider
    

    And what you want is use the method GetUserNameByEmail which is inside the provider implementation. There are two ways to call this method, through:

    MyEnterprise.MyArea.MyProviders.CustomProvider.GetUserNameByEmail(email)
    

    Which will not fire the Initialize method as you are calling it by yourself, on the other hand if your call is:

    Membership.GetUserNameByEmail(email)
    

    The Initialize method will be called if necessary, I assume this is on the base constructor or something (didn't dig more).

    Hope this helps. - E.

提交回复
热议问题