- protected void Application_Start() {
- AreaRegistration.RegisterAllAreas();
- RegisterRoutes(RouteTable.Routes);
- Application["SystemUser"] = TUser.GetUserByIdentifier("system").UID;
- InitializeSolrInstances();
- SearchIndexer.DoIndex();
- StartRatingTimer();
- SolrManager.RecalculateMostRequested();
- }
- private static void InitializeSolrInstances() {
- SolrConfigurationManager.InitSolrConnection<OfferItemPresenter>(Resources.ApplicationResources.SolrServiceURL + "/offer");
- SolrConfigurationManager.InitSolrConnection<SavedQueryItemPresenter>(Resources.ApplicationResources.SolrServiceURL + "/savedquery");
- SolrConfigurationManager.InitSolrConnection<TopProductsPresenter>(Resources.ApplicationResources.SolrServiceURL + "/topproducts");
- SolrConfigurationManager.InitSolrConnection<TopSellersPresenter>(Resources.ApplicationResources.SolrServiceURL + "/topsellers");
- SolrConfigurationManager.InitSolrConnection<MostRequestedItemPresenter>(Resources.ApplicationResources.SolrServiceURL + "/mostrequested");
- SolrConfigurationManager.InitSolrConnection<MostRequestedQuery>(Resources.ApplicationResources.SolrServiceURL + "/requestedquery");
- }
- private void StartRatingTimer() {
- _LastRatingRenewedTime = DateTime.Now;
- DateTime CurrentTime = DateTime.Now;
- DateTime StartTime = new DateTime(2011,1,1);
- GlobalSettings.ReIndexMainSolrCores(StartTime,CurrentTime);
- Timer OfferAndUserRatingRenewerTimer = new Timer() {
- /*Timer interval for 24 hours*/
- Interval = 24 * 60 * 60 * 1000,Enabled = true };
- OfferAndUserRatingRenewerTimer.Elapsed += new ElapsedEventHandler(OfferAndUserRatingRenewerTimer_Elapsed);
- }
- public void OfferAndUserRatingRenewerTimer_Elapsed(Object Sender,ElapsedEventArgs e) {
- GlobalSettings.ReIndexMainSolrCores(_LastRatingRenewedTime,e.SignalTime);
- _LastRatingRenewedTime = e.SignalTime;
- }
我根本不使用HttpContext的Response或Request属性.全局asax本身也不在调用的方法内.帮我.
响应在此上下文中不可用.
说明:在执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误的更多信息及其在代码中的位置.
异常详细信息:System.Web.HttpException:响应在此上下文中不可用.
源错误:
在执行当前Web请求期间生成了未处理的异常.有关异常的来源和位置的信息可以使用下面的异常堆栈跟踪来识别.
堆栈跟踪:
- [HttpException (0x80004005): Response is not available in this context.]
- System.Web.Util.HttpEncoder.get_Current() +11406684
- System.Web.HttpUtility.UrlEncode(String str,Encoding e) +137
- SolrNet.Impl.SolrConnection.<Get>b__0(KeyValuePair`2 input) +89
- SolrNet.Utils.<Select>d__1a`2.MoveNext() +612
- SolrNet.Utils.Func.Reduce(IEnumerable`1 source,TResult startValue,Accumulator`2 accumulator) +393
- SolrNet.Impl.SolrConnection.Get(String relativeUrl,IEnumerable`1 parameters) +908
- SolrNet.Impl.SolrQueryExecuter`1.Execute(ISolrQuery q,QueryOptions options) +195
- SolrNet.Impl.SolrBasicServer`1.Query(ISolrQuery query,QueryOptions options) +176
- SolrNet.Impl.SolrServer`1.Query(ISolrQuery query,QueryOptions options) +176
- TebeComSearchEngine.SolrManager.RecalculateMostRequested() in SolrManager.cs:77
- TebeCom.MvcApplication.Application_Start() in Global.asax.cs:101
- [HttpException (0x80004005): Response is not available in this context.]
- System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context,HttpApplication app) +4043621
- System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext,HttpContext context,MethodInfo[] handlers) +191
- System.Web.HttpApplication.InitSpecial(HttpApplicationState state,MethodInfo[] handlers,IntPtr appContext,HttpContext context) +352
- System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext,HttpContext context) +407
- System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +375
- [HttpException (0x80004005): Response is not available in this context.]
- System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11612256
- System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141
- System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr,HttpContext context) +4842149`
解决方法
不过,正如VinayC在他对Darin答案的评论中指出的那样:
Actually,it appears to be a bug. From
reflector,actual code appears to be
“if (null != current && null !=
current.Response && …)” where
current is current http context. Issue
here is that Response getter throws an
exception,instead of returning null
而不是扔这个过分描述性的异常(毫无疑问,他们试图有帮助),他们应该刚刚返回null,并引用null引用异常发生.在这种情况下,他们只是检查null,所以异常不会发生!如果还没有,我会将其报告为错误.
不幸的是,这对你来说意味着你几乎别无选择,只能在经典模式下运行.从技术上讲,您可以在您在application_start中生成的线程中调用TebeComSearchEngine.SolrManager.RecalculateMostRequested(),并延迟其执行,直到应用程序完成启动.据我所知,没有一种可靠的方法来以编程方式发出申请的结束,所以这种方法可能会有点混乱.
如果你这么做,那么你可能会实现延迟的启动机制.相对于惩罚网站的第一个访问者来说,似乎并不太糟糕.