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.
This commit is contained in:
Qingyu Zhou
2015-09-29 15:33:45 -07:00
parent 9bafa7ff9a
commit e75b3aa06c

View File

@@ -158,6 +158,17 @@ namespace Orchard.Mvc {
get { return false; }
}
/// <summary>
/// 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.
/// </summary>
public override string AnonymousID {
get {
return Guid.NewGuid().ToString("D", CultureInfo.InvariantCulture);
}
}
// empty collection provided for background operation
public override NameValueCollection Form {
get {