Bug in minicart
Posted: Mon Jan 26, 2009 12:56 am
Hi
We just spent some time figuring out an issue that has been reported on these forums but never answered.
The issue is this: the first time somebody browses to your site, they get an object null exception.
This is caused by a potential design flaw in the minicart. This component overrides the preinit event in order to find out who the current user is so that the basket can be populated.
It does this by calling a method in Token.Instance.User in order to find out who the user is. HOWEVER, the first time the user browses to the site, there is no session cookie, and the PreInit event is too early in the request/response cycle for the session cookie to be created. The Token.Instance.User object seems to have some deficiencies in that it returns without problem, but then when you try and do something with the basket, you get the null reference.
We did discover that if the user is unknown, the UserID returned for the User object is 0, so we fixed the problem by adding some code to the minicart to hide it if the UserID is zero.
If I'm honest, I regard this fix as being a bodge - the Token.Instance.User should have some clear way of communicating that the user is unknown.
All the Best
Tony
We just spent some time figuring out an issue that has been reported on these forums but never answered.
The issue is this: the first time somebody browses to your site, they get an object null exception.
This is caused by a potential design flaw in the minicart. This component overrides the preinit event in order to find out who the current user is so that the basket can be populated.
It does this by calling a method in Token.Instance.User in order to find out who the user is. HOWEVER, the first time the user browses to the site, there is no session cookie, and the PreInit event is too early in the request/response cycle for the session cookie to be created. The Token.Instance.User object seems to have some deficiencies in that it returns without problem, but then when you try and do something with the basket, you get the null reference.
We did discover that if the user is unknown, the UserID returned for the User object is 0, so we fixed the problem by adding some code to the minicart to hide it if the UserID is zero.
If I'm honest, I regard this fix as being a bodge - the Token.Instance.User should have some clear way of communicating that the user is unknown.
All the Best
Tony