From e75b3aa06c573a207c95496d85cfe5f7b02ce76c Mon Sep 17 00:00:00 2001 From: Qingyu Zhou Date: Tue, 29 Sep 2015 15:33:45 -0700 Subject: [PATCH] CookieCultureSelector.EvaluateResult is caught with NotImplementedException The issue is caused by CookieCultureSelector is expecting a working implementation of HttpRequestBase.AnonymousID, yet in one case that wont'be true. During background task execution, which is started by SweepGenerator on a background thread without real HTTP request, the HttpRequestBase object is created using HttpRequestPlaceholder, which is trying to simulate a valid HTTP Request to some extent, particularly leaving its property AnonymousID not implemented. However, CookieCultureSelector.EvaluateResult is expecting context.Request.AnonymousID being implemented in some way. This could be seen as a bug in Orchard.CultureSelector, as one can justify that it should be aware of fake HttpRequestBase object. On the other hand, this could be an Orchard bug as well, if the philosophy is to keep the users of HttpRequestBase objects ignorant of the actual implementation. I prefer the latter, thus this fix. --- src/Orchard/Mvc/MvcModule.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Orchard/Mvc/MvcModule.cs b/src/Orchard/Mvc/MvcModule.cs index f44c5cd4a..9b289749d 100644 --- a/src/Orchard/Mvc/MvcModule.cs +++ b/src/Orchard/Mvc/MvcModule.cs @@ -158,6 +158,17 @@ namespace Orchard.Mvc { get { return false; } } + /// + /// Create an anonymous ID the same way as ASP.NET would. + /// Some users of an HttpRequestPlaceHolder object could expect this, + /// say CookieCultureSelector from module Orchard.CulturePicker. + /// + public override string AnonymousID { + get { + return Guid.NewGuid().ToString("D", CultureInfo.InvariantCulture); + } + } + // empty collection provided for background operation public override NameValueCollection Form { get {