find a location for property in a new city

Thursday, 18 November 2010

Static Membership helper class causing problems with MembershipProvider

I was having a problem where after a user changes their password using my custom MembershipProvider it was being updated in the database but didn't seem to be propagating to my application. So if they tried to log in they would be expected to provide their old password even though there was a new password in the database.

It is almost as if Membership didn't particularly care what has changed in the database and it kept on just doing its own thing.

Almost as if Membership is a static class... oh right it is

I thought the Membership was acting as if it was a singleton or something and never going through its constructor which sets a new UserService() to the UserService property (the service which ultimately gets the users' data). Maybe it is something to do with the fact that MEMBERSHIP IS A STATIC CLASS! Of course.

Membership was using my MembershipProvider but only ever instantiating it once due to its static nature so the UserService was keeping the old version even if the data had been edited. My fix was to make sure that the MembershipService property returned a new MembershipService() each time it is called.

So for context I changed this code in MyMembershipProvider:
public MyMembershipProvider()
{
    UserService = new UserService();
}

public UserService UserService { get; set; }

To this:
public MyMembershipProvider() {}

public UserService UserService
{
    get { return new UserService(); }
}

Follow britishdev on Twitter

5 comments:

  1. good info, thank for share

    ReplyDelete
  2. Thank you for sharing a superb information. I am impressed by the details that you have on this blog.
    Santander Mobile Banking For PC

    ReplyDelete

  3. نقل عفش من الرياض الى جدة شركة نقل عفش من الرياض الى جدة


    نقل عفش من الرياض الى جدة نقل عفش من الرياض الى مكة


    ReplyDelete
  4. I was having a problem where after a user changes their password using my custom MembershipProvider it was being updated in the database but didn't seem to be propagating to my application. So if they tried to log in they would be expected to provide their old password even though there was a new password in the database. single bed sheet , comforter online , gul ahmed bed sheets online shopping , bridal bed sheet online , king size bedspread sets , single cotton mattress , blanket shop near me , single bed razai cover , best sofa covers online , pakistani cotton suits

    ReplyDelete
  5. Great Article
    Cloud Computing Projects




    Networking Projects



    Final Year

    Projects for CSE





    JavaScript Training in Chennai



    JavaScript

    Training in Chennai




    The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals,

    Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer.

    Angular Training

    ReplyDelete