Try our conversational search powered by Generative AI!

CustomerContext.Current is becoming null even after login


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


Venkata Phani Kumar R

Edited, Mar 30, 2017 9:28

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

Mar 30, 2017 10:39

Hi Quan,

PrincipalInfo.Current.Principal.Identity Is null.



Mar 30, 2017 10:49

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 

Mar 30, 2017 11:04

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.


Venkata Phani kumar R

Apr 03, 2017 7:57

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.

Apr 03, 2017 8:55

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

// For more information on configuring authentication,
// please visit

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 =
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => manager.GenerateUserIdentityAsync(user))


// 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.


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.