Page 1 of 1

Force Login - No Anonymous Shopping

Posted: Sun Feb 20, 2011 10:16 am
by aferrara
As a new AC implementer my first site brought a couple of requirements that do not appear to be "in the box". In my site, the users cannot shop without logging in first. I couldn't find any posts describing exactly how this was accomplished by the community so I implemented a simple technique, although I had to insert a function in each page I needed to protect. I did this by inserting the following logic in pre_init on each page:

Code: Select all

protected void Page_PreInit(object sender, EventArgs e)
{
        if (Token.Instance.User == null || Token.Instance.User.IsAnonymous)
            Response.Redirect("~/Login.aspx");
} 
This seems to work OK and using source control I can manage this simple difference when I upgrade later without a problem, but, since I am not an AC expert I'm wondering if there is something I overlooked or even a quicker/easier way to do this.

Regards,
Art

Re: Force Login - No Anonymous Shopping

Posted: Sun Feb 20, 2011 3:33 pm
by mikek
You can enforce account sign in for all site visitors by adding "allow" authorization rule for authenticated users only. Just add the the code below before the </system.web> in your site
web.config file.

<authorization>
<deny users="?" />
<allow users="*" />
</authorization>

This apples to any asp.net based site and is not specific to AbleCommerce.

Re: Force Login - No Anonymous Shopping

Posted: Tue Apr 16, 2013 4:48 pm
by Tea-Dev
The changes to web.config do work, but for some reason, the formatting is all messed up as it odes not inherit any css or layout. How can we invoke the same with the css or layout formatting?