Get CustomerId from Razor

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 anni tempo fa
Hi,

I need the CustomerId within the frontend and see there's a cookie Nop.customer available.
Is there also a way to get this id from the framework?

Thanks

Andre
11 anni tempo fa
_workContext.CurrentCustomer.Id

get a IWorkContext via ctor injection:

IWorkContext workContext
11 anni tempo fa
Thanks - but maybe you can give me some more help with ...?
For ctor I found this MS thread http://msdn.microsoft.com/en-us/library/ff650802.aspx but I've no idea how to make it work with your solution...
11 anni tempo fa
in your view you have a WorkContext property, use it like this:

@{
var id = WorkContext.CurrentCustomer.Id ;
}


In other parts of your code, for example a controller, dependency injection can be used:


private IWorkContext _workContext ;

public SomeController( IWorkContext workContext ..... )
{
_workContext = workContext;
}


where SomeController is the constructor
11 anni tempo fa
Thenks for your support!
10 anni tempo fa
Thx
9 anni tempo fa
hello keesjan

as per you say i am try to inject  IWorkContext in WebStoreContext and also StoreService.

but when we run project it give's errors

on ContainerManager.cs(line no 113)

An unhandled exception of type 'System.StackOverflowException' occurred in Autofac.dll


please help me

regards,
jatin
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.