How can I check if a user is logged in?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
Please I need to check or verify if a user is logged in Programmatically.
Basically I am creating another page on nopCommerce, where by some controls will be disabled until the user is logged in. Help in needed. Thanks.
12 years ago
you can track who is online in admin panel. just go to Customers>Online Customers then tick module enabled save it and refresh your browser. all users will be listed below.
12 years ago
wxDevelopment wrote:
you can track who is online in admin panel. just go to Customers>Online Customers then tick module enabled save it and refresh your browser. all users will be listed below.


Thanks for the quick response but that's not what I meant. I need to check this programmatically from an additional page on the shopping cart, not the admin.

An example could be;

           if (User.Current.IsLoggedin)
            {
                //To do Logic here
            }
            else {
           //Do something else
             }

How can I do this on nopcommerce? Anybody?  Thanks
12 years ago
HttpContext.Current.User.Identity.IsAuthenticated;
12 years ago
hezyz wrote:
HttpContext.Current.User.Identity.IsAuthenticated;


Thanks hezyz. Worked like is new.
10 years ago
Has anyone followed this suggestion and run into a problem?  I'm replicating the Login method of the CustomerController to authenticate a user on a remote service, such as a PhoneGap app.  While I can get the user signed in/logged in, I seem never to be calling whatever is authenticating the user.  

Can someone tell me where and when does nopCom indicate that the user is authenticated?

I'm using nopCommerce 3.20.
6 years ago
if want to put an IF clause in the views i.e. .cshtml

I observe that
 HttpContext.Current.User.Identity.IsAuthenticated 
always returns a true ..


even after the user has logged out
6 years ago
You can also use

var isAuthenticated = Nop.Core.Infrastructure.EngineContext.Current.Resolve<Nop.Core.IWorkContext>().CurrentCustomer.IsRegistered();
3 years ago
Hi dear,
I found this method is not working in 4.30
So I found another way

var isRegisterCustomer = customerService.IsRegistered(workContext.CurrentCustomer);


to have this worked you have to include few lines into your Razor view
@using Nop.Core
@using Nop.Services.Customers

@inject IWorkContext workContext
@inject ICustomerService customerService
3 years ago
add this on top

@inject IWorkContext workContext

then  you can use this

bool isAuthenticated = workContext.CurrentCustomer.CustomerRoles.Where(x => x.SystemName == "Guests").ToList().Count() > 0 ? false : true;
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.