I'm trying to find a solution to allow users to only be able to view the homepage, but when they click on anything it re-directs to the register page. I tried playing around with the access control list, but if you turn navigation off for guests they can't even view the homepage.
I'm trying to find a solution to allow users to only be able to view the homepage, but when they click on anything it re-directs to the register page. I tried playing around with the access control list, but if you turn navigation off for guests they can't even view the homepage.
Any ideas would be much appreciated.
One very easy solution is to:
1) Open Root.Head.cshtml 2) Add the following at the very top (after using statements)
@* other using statements ... *@ using Nop.Core.Domain.Customers;
@{ if (WorkContext.CurrentCustomer.IsGuest() && Request.Url.AbsolutePath != "/" && Request.Url.AbsolutePath != "login") // and other pages you want to allow { Response.Redirect("~/", true); } }
Not the most sophisticated solution, but it's quick and it works! :)
Forgot to mention, there can be a bug in my earlier code due to string comparison being case-sensitive. So we need to make sure we ignore the case. A better version is to use:
Good catch! I just had to add not conditions to each inequality:
@{ 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); } }
Good catch! I just had to add not conditions to each inequality:
@{ 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); } }
Yeap! Sounds good! :)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.