New membership activation, not recognized as member until re-login

Hello all,

This question is sort of related to a previous posting by me here: http://www.imiscommunity.com/redirect_to_billing_page_after_auto_login_forcing_re_login

I have captured when a user has paid for their membership, and have updated their status (CustomerTypeCode) to a Member.

The problem is, the user cannot access any members only content immediately. They must first logout, then log back in. Only then can they access members only content.

I'm not sure how to get around this problem. I've tried a few things, including programmatically logging them out and logging them back in, but nothing seems to work.

The code I used to programmatically re-login the user is below (basically the same code that solved my earlier problem). Perhaps there's something still not being set identifying the user as a member? (This code is run right after updating the contact's CustomerTypeCode and saving it).

[code]

string contactLogin = contact.UserSecurity.WebLoginId;
using (Asi.Security.SecurityContext.Impersonate(contactLogin))
{
       FormsAuthentication.SignOut();
       Asi.Security.SecurityContext.LogonByUserId(contactLogin);
       Session["LoginUser"] = CContactUser.LoginByWebLogin(contactLogin);
       FormsAuthentication.SetAuthCookie(Asi.Security.AppPrincipal.CurrentIdentity.Name, false);
}

[/code]

Any help is greatly appreciated.

Thanks,
Colin

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Hi, I think you need to

Hi,

I think you need to establish appcontext once you call SetAuthCookie method.
 
string contactLogin = contact.UserSecurity.WebLoginId;
using (Asi.Security.SecurityContext.Impersonate(contactLogin))
{
       FormsAuthentication.SignOut();
       Asi.Security.SecurityContext.LogonByUserId(contactLogin);
       Session["LoginUser"] = CContactUser.LoginByWebLogin(contactLogin);
       FormsAuthentication.SetAuthCookie(Asi.Security.AppPrincipal.CurrentIdentity.Name, false);
      Asi.Web.Security.EstablishAppContext(Context);       //new line added - this loads new security levels for newly created user.
}
Not tested. I believe this will work.
Balaji

Thanks for the reply,

Thanks for the reply, Balaji.

We've gone with an interim fix for now (redirect through a logout back to login), and won't be coming back to this issue right away.

Once I get the opportunity, I'll give your suggestion a shot and let you know how it goes.

Thanks again!
Colin

You were right!

Thanks Balaji!

Finally got around to testing your suggestion and it works like a charm.