Proper way to check authentication in razor view?

7 年 前
Hi I was wondering the correct way to check if a user is authenticated in a razor view in 3.1?

I wanted to hide parts of the navigation etc depending on if a user is logged in.. can you just use @User.Identity.IsAuthenticated

or is there a more correct way?
7 年 前
See this post -
7 年 前
Thanks for letting me know.. I was hoping to just add this to a base model or something like that but im using the nop-template's mega menu so hooking it in without the source is a little crap..
7 年 前
I ended up using this:
1 个月 前
Hi there,
I found method which is working in 4.30

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