Allow guests to view homepage only

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
8 years ago
How can I match in this code , also URL of password recovery ?

/passwordrecovery is not sufficient because it has more random parameters

/passwordrecovery/confirm?token=0aa01fca-
7 years ago
I'm having an issue when I paste the code to Nop 3.80 _Root.Head.cshtml

@{
    if (WorkContext.CurrentCustomer.IsGuest() &&
        !(Request.Url.AbsolutePath.Equals("/", StringComparison.InvariantCultureIgnoreCase)) &&
        !(Request.Url.AbsolutePath.Equals("/t/PageNotFound", StringComparison.InvariantCultureIgnoreCase)) &&
        !(Request.Url.AbsolutePath.Equals("/login", StringComparison.InvariantCultureIgnoreCase)))// and other pages you want to allow
    {
        Response.Redirect("/t/PageNotFound", true);
    }
}

The error is WorkContext.
Can anyone please help me on it?
7 years ago
popolun wrote:
I'm having an issue when I paste the code to Nop 3.80 _Root.Head.cshtml

@{
    if (WorkContext.CurrentCustomer.IsGuest() &&
        !(Request.Url.AbsolutePath.Equals("/", StringComparison.InvariantCultureIgnoreCase)) &&
        !(Request.Url.AbsolutePath.Equals("/t/PageNotFound", StringComparison.InvariantCultureIgnoreCase)) &&
        !(Request.Url.AbsolutePath.Equals("/login", StringComparison.InvariantCultureIgnoreCase)))// and other pages you want to allow
    {
        Response.Redirect("/t/PageNotFound", true);
    }
}

The error is WorkContext.
Can anyone please help me on it?


Try the bellow code




@{
var IWorkContext WorkContext = EngineContext.Current.Resolve<IWorkContext>();
    if (WorkContext.CurrentCustomer.IsGuest() &&
        !(Request.Url.AbsolutePath.Equals("/", StringComparison.InvariantCultureIgnoreCase)) &&
        !(Request.Url.AbsolutePath.Equals("/t/PageNotFound", StringComparison.InvariantCultureIgnoreCase)) &&
        !(Request.Url.AbsolutePath.Equals("/login", StringComparison.InvariantCultureIgnoreCase)))// and other pages you want to allow
    {
        Response.Redirect("/t/PageNotFound", true);
    }
}
7 years ago
Hi,

Thank you for helping me on the coding.
However, it still shows an error.
I took the screenshot here.
http://sendfile.cc/uploads/file/201608/0.046885001471574112.png

Thank You
7 years ago
popolun wrote:
Hi,

Thank you for helping me on the coding.
However, it still shows an error.
I took the screenshot here.
http://sendfile.cc/uploads/file/201608/0.046885001471574112.png

Thank You


Ok here is the solution. Please add the reference at the view

@using Nop.Core;
@using Nop.Core.Domain.Common;
@using Nop.Core.Infrastructure;
@using Nop.Core.Domain.Customers;

the add the bellow code

   var currentCustomer = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer;
    if (currentCustomer.IsGuest() &&
        !(Request.Url.AbsolutePath.Equals("/", StringComparison.InvariantCultureIgnoreCase)) &&
        !(Request.Url.AbsolutePath.Equals("/t/PageNotFound", StringComparison.InvariantCultureIgnoreCase)) &&
        !(Request.Url.AbsolutePath.Equals("/login", StringComparison.InvariantCultureIgnoreCase)))// and other pages you want to allow
    {
        Response.Redirect("/t/PageNotFound", true);
    }

I have tested it and it seems it is working for 3.8
5 years ago
Hello to all,

Is there any way to allow access to some pages only to a specific customer group?
5 years ago
steelgr wrote:
Hello to all,

Is there any way to allow access to some pages only to a specific customer group?

While creating/editing a topic page in Advanced mode you have ACL options to limit which customer roles can view it
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.