Accessing 'context' from an external library

Pedro Graca asked on September 17, 2015 17:15

Good afternoon,

I'm currently developing an API that interacts between the front end (using AngularJS) and an external library (BLL). However, when I try to query anything from the context on the BLL nothing is passed in from Kentico although this BLL is referenced on Kentico project e.g.

ShoppingCartInfo cartObj = ECommerceContext.CurrentShoppingCart;

CustomerInfo currentCustomer = ECommerceContext.CurrentCustomer;

CurrentUserInfo userObj = MembershipContext.AuthenticatedUser;

Any advice?

Best regards, Pedro

Recent Answers


Dawid Jachnik answered on September 17, 2015 21:52

Hello Pedro,

Did you initialize Kentico instance before making API calls ?

When working with Kenticp API in an external application, the default user context is not avalible.

But you can wrap your code in using statement with declared CMSActionContext of the aapproriate UserInfo object as parameter:

UserInfo user = UserInfoProvider.GetUserInfo("my@username.com");

using (new CMSActionContext(user))
{
    ShoppingCartInfo cartObj = ECommerceContext.CurrentShoppingCart;
    CustomerInfo currentCustomer = ECommerceContext.CurrentCustomer;
    CurrentUserInfo userObj = MembershipContext.AuthenticatedUser;
}

You can find more info in the documentation

2 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.