Check if logged in through the Root.cshtml nop 2.3

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Hace 12 años
is there a way to Check if logged in through the Root.cshtml nop 2.3
if the visitor is logged in I will display a different menu than if they are not logged in.
Hace 12 años
scripter wrote:
is there a way to Check if logged in through the Root.cshtml nop 2.3
if the visitor is logged in I will display a different menu than if they are not logged in.


Sure. I've provided some sample code (untested).


@{

using Nop.Core;
using Nop.Core.Infrastructure;
using Nop.Services.Customers;
            bool isRegistered = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer.IsRegistered();
}


p.s.

I this logic is better suited for an action instead of the view and the pass the value to the view that is responsible for determining which menu to use.
Hace 12 años
I have done what you suggested which appears to work but when I try to do a If statement to determine which partial header to put on it blows up my page.

Here is my if statement which is where I am pretty sure the problem is

@{
                if (isRegistered)
                {
                    Html.Partial("HeaderLoggedin");
                }
                else
                {
                    Html.Partial("Header");
                }
            }

if you see what is wrong with this please let me know
Hace 12 años
scripter wrote:
I have done what you suggested which appears to work but when I try to do a If statement to determine which partial header to put on it blows up my page.

Here is my if statement which is where I am pretty sure the problem is

@{
                if (isRegistered)
                {
                    Html.Partial("HeaderLoggedin");
                }
                else
                {
                    Html.Partial("Header");
                }
            }

if you see what is wrong with this please let me know


Can you provide the error message and stack trace? At first glance it looks right (although you might have semicolons render too).
Hace 12 años
skyler.severns wrote:
I have done what you suggested which appears to work but when I try to do a If statement to determine which partial header to put on it blows up my page.

Here is my if statement which is where I am pretty sure the problem is

@{
                if (isRegistered)
                {
                    Html.Partial("HeaderLoggedin");
                }
                else
                {
                    Html.Partial("Header");
                }
            }

if you see what is wrong with this please let me know

Can you provide the error message and stack trace? At first glance it looks right (although you might have semicolons render too).



Its not giving error but just not rendering the Header at all
The If statement just is not being processed like I thought it would.
if I didnt include the semicolons then it errors on me so that I why I added them
Hace 12 años
Figured out that problem
I did not include the @ symbol in there



@{
                if (isRegistered)
                {
                    @Html.Partial("HeaderLoggedin");
                }
                else
                {
                    @Html.Partial("Header");
                }
            }
Hace 12 años
Thank you so much for your help. This is my first shot at this new NopCommerce and with Razor so this is a huge learning experience for me..
Hace 3 años
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
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.