London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

CustomerContext.Current is becoming null even after login

Vote:
 

Hi All,

I have an issue with CustomerContext.Current . In CMS pages CustomerContext.Current is giving the right detial of the login person.  Where as on Commerce pages eg: Product Details pages ,CustomerContext.Current is  Null. 

PrincipalInfo.Current.Principal.GetCustomerContact()  is also null.

if (System.Web.HttpContext.Current.Request.LogonUserIdentity != null &&
System.Web.HttpContext.Current.Request.LogonUserIdentity.IsAuthenticated)  is true. 

I am using form authentication . Owin Components are instaaled to use the service api features. 

Can some one suggest me the instructions to trouble shoot this issue. 

Commerce version is 10.4.2

Regargds

Venkata Phani Kumar R

#176930
Edited, Mar 30, 2017 9:28
Vote:
 

That's very strange. CustomerContext.Current is a static property and it should not be different between pages.

What do you have in PrincipalInfo.Current.Principal? If PrincipalInfo.Current.Principal.GetCustomerContact() returns null then it's likely because PrincipalInfo.Current.Principal is null or PrincipalInfo.Current.Principal.Identity is null

#176932
Mar 30, 2017 10:39
Vote:
 

Hi Quan,

PrincipalInfo.Current.Principal.Identity Is null.

regards

phani

#176934
Mar 30, 2017 10:49
Vote:
 

QuickSilver is using Owin/AspnetIdentity and those properties work perfectly. I suspect it's something in your configuration - so as usual - I would suggest you to contact our developer support service for further assistance 

#176935
Mar 30, 2017 11:04
Vote:
 

Hi Quan,

I have implmented the AspIdentity provider.  However situation is same. 

I am facing the issue on webapi calls .

PrincipalInfo.Current.Principal.GetCustomerContact() is always null.

Regards

Venkata Phani kumar R

#177024
Apr 03, 2017 7:57
Vote:
 

Can you post your Startup.cs file here, if it does not contain any sensitive information?

This is a less known area and I've never seen this error, so I'm not sure I can spot anything. We should be able to say more if we have the entire solution which can reproduce the problem.

#177025
Apr 03, 2017 8:55
Vote:
 

public class Startup
{
private readonly ILogger _logService = EPiServer.Logging.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

// For more information on configuring authentication,
// please visit http://world.episerver.com/documentation/Items/Developers-Guide/Episerver-CMS/9/Security/episerver-aspnetidentity/

private readonly IConnectionStringHandler _connectionStringHandler;

public Startup() : this(ServiceLocator.Current.GetInstance<IConnectionStringHandler>())
{
// Parameterless constructor required by OWIN.
}

public Startup(IConnectionStringHandler connectionStringHandler)
{
_connectionStringHandler = connectionStringHandler;
}
public void Configuration(IAppBuilder app)
{
// Add CMS integration for ASP.NET Identity
app.AddCmsAspNetIdentity<SiteUser>(new ApplicationOptions
{
ConnectionStringName = _connectionStringHandler.Commerce.Name
});

// Use cookie authentication
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/User"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity =
SecurityStampValidator.OnValidateIdentity<ApplicationUserManager<SiteUser>,SiteUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => manager.GenerateUserIdentityAsync(user))
}
});

app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

// Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process.
app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));

// Enables the application to remember the second login verification factor such as phone or email.
// Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from.
// This is similar to the RememberMe option when you log in.
app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

}
}

#177026
Apr 03, 2017 8:59
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.