添加51Degrees移动检测库后,我的ASP.NET MVC 3项目慢慢爬行。 <log logFile="~/bin/App_Data/51Log.txt" logLevel="Info" />
部分中<fiftyOne>
定义的51Degrees日志文件显示每个请求都重新加载设备库,为每个请求添加2-3秒的延迟:
2011-10-22T14:17:34.9863774Z - 8436 - Info - Loaded 14691 devices using 11640 strings in 1882ms
2011-10-22T14:17:50.8442844Z - 8436 - Info - Loaded 14691 devices using 11640 strings in 1820ms
2011-10-22T14:17:57.2756523Z - 8436 - Info - Loaded 14691 devices using 11640 strings in 1928ms
2011-10-22T14:18:01.0488681Z - 8436 - Info - Loaded 14691 devices using 11640 strings in 1886ms
2011-10-22T14:18:04.6790757Z - 8436 - Info - Loaded 14691 devices using 11640 strings in 1862ms
此外,在web.config中设置<fiftyOne>
<log ... logLevel="Debug">
会在启动时抛出以下异常:
Storage scopes cannot be created when _AppStart is executing.
如果我创建一个空白的ASP.NET MVC 4应用程序并添加最新的51Degrees 2.0.3.2 NuGet包,那么一切都很完美。正如预期的那样,日志反映出二进制数据尽管多次请求只被加载一次(51Degrees.mobi-Lite-2012.01.05.dat)。
非常乐观,我将所有主要的MVC 3项目代码复制到一个新的ASP.NET MVC 4项目并重新添加了最新的51Degrees包,但问题再次出现。必须与我的某个软件包不兼容,或者是一个奇怪的设置。
日志显示正在为每个请求重新加载库:
2012-01-18T11:50:02.5026920Z - 11928 - Info - Creating provider from binary data file '~\App_Data\51Degrees.mobi-Lite-2012.01.05.dat'.
2012-01-18T11:50:02.8137098Z - 11928 - Info - Created provider from binary data file '~\App_Data\51Degrees.mobi-Lite-2012.01.05.dat'.
2012-01-18T11:50:07.7419917Z - 11928 - Info - Creating provider from binary data file '~\App_Data\51Degrees.mobi-Lite-2012.01.05.dat'.
2012-01-18T11:50:08.0170074Z - 11928 - Info - Created provider from binary data file '~\App_Data\51Degrees.mobi-Lite-2012.01.05.dat'.
2012-01-18T11:50:10.4191448Z - 11928 - Info - Creating provider from binary data file '~\App_Data\51Degrees.mobi-Lite-2012.01.05.dat'.
2012-01-18T11:50:10.7251623Z - 11928 - Info - Created provider from binary data file '~\App_Data\51Degrees.mobi-Lite-2012.01.05.dat'.
延迟远小于XML数据文件(300ms vs 3000ms),但它仍然会导致明显的延迟。
两个项目'51Degrees.mobi.config文件是相同的,在我的web.config中,这是我加载的模块:
<modules>
<remove name="Detector"/>
<add name="Detector" type="FiftyOne.Foundation.Mobile.Detection.DetectorModule, FiftyOne.Foundation"/>
</modules>
什么可能导致51Degrees库在每个请求上重新加载?
答案 0 :(得分:7)
这是因为日志文件放在bin文件夹中。只要bin文件夹中发生任何更改,工作进程就会重新启动。将日志文件移动到〜/ App_Data文件夹,您将发现问题将得到解决。感谢您使用51Degrees.mobi。
答案 1 :(得分:0)
我从CodePlex抓取了MVC3MobileDect演示应用程序。我使用ASP.NET Web开发服务器和IIS Express运行它,并且没有表现出库存重新加载每个请求到Web服务器的所有设备的问题。
此外,演示项目不包括在Application_Start中修改BrowserCapabilitiesProvider(但是,即使我添加它也仍然有效。)
此时,假设您正在使用开源版本,我建议抓取Foundation程序集的源代码,并从
中设置断点开始 \Foundation\Mobile\Detection\Wurfl\Provider.cs
(可能在InitWurflFiles
方法中)。
也许调用堆栈中会有一些东西可以帮助你更好地理解正在发生的事情。
或者,将演示项目的配置与您的Web应用程序进行比较。