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.
12 years ago
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.
12 years ago
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.
12 years ago
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
12 years ago
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).
12 years ago
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
12 years ago
Figured out that problem
I did not include the @ symbol in there



@{
                if (isRegistered)
                {
                    @Html.Partial("HeaderLoggedin");
                }
                else
                {
                    @Html.Partial("Header");
                }
            }
12 years ago
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..
3 years ago
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.