protected void Application_Start(Object sender, EventArgs e) { // 注册路由 RegisterRoutes(RouteTable.Routes); OpacApplication app = null; try { int nRet = 0; string strError = ""; #if NO string strErrorLogDir = this.Server.MapPath(".\\log"); PathUtil.CreateDirIfNeed(strErrorLogDir); string strErrorLogFileName = PathUtil.MergePath(strErrorLogDir, "error.txt"); #endif try { string strDataDir = ""; // reutrn: // -1 error // 0 not found start.xml // 1 found start.xml nRet = OpacApplication.GetDataDir(this.Server.MapPath("~/start.xml"), out strDataDir, out strError); if (nRet == -1) { strError = "搜寻配置文件start.xml时出错: " + strError; #if NO OpacApplication.WriteErrorLog(strErrorLogFileName, strError); #endif OpacApplication.WriteWindowsLog(strError); Application["errorinfo"] = strError; return; } if (nRet == 0) { #if NO // 实在没有start.xml文件, 默认虚拟目录就是数据目录 strDataDir = this.Server.MapPath("."); #endif // 2014/2/21 // 不再允许虚拟目录中 start.xml 没有的情况 OpacApplication.WriteWindowsLog("OpacApplication.GetDataDir() error : " + strError); Application["errorinfo"] = strError; return; } app = new OpacApplication(); Application["app"] = app; // string strHostDir = this.Server.MapPath("."); string strHostDir = Path.GetDirectoryName(this.Server.MapPath("~/start.xml")); // 2015/7/20 nRet = app.Load( false, strDataDir, strHostDir, out strError); if (nRet == -1) { #if NO OpacApplication.WriteErrorLog(strErrorLogFileName, strError); #endif // TODO: 预先试探一下写入数据目录中的错误日志文件是否成功。如果成功,则可以把错误信息写入那里 OpacApplication.WriteWindowsLog(strError); // Application["errorinfo"] = strError; app.GlobalErrorInfo = strError; } else { nRet = app.Verify(out strError); if (nRet == -1) { #if NO OpacApplication.WriteErrorLog(strErrorLogFileName, strError); #endif OpacApplication.WriteWindowsLog(strError); // Application["errorinfo"] = strError; app.GlobalErrorInfo = strError; } } OpacApplication.WriteWindowsLog("dp2OPAC Application 启动成功", EventLogEntryType.Information); } catch (Exception ex) { strError = "装载配置文件 opac.xml 出错: " + ExceptionUtil.GetDebugText(ex); #if NO OpacApplication.WriteErrorLog(strErrorLogFileName, strError); #endif OpacApplication.WriteWindowsLog(strError); if (app != null) { app.GlobalErrorInfo = strError; } else { Application["errorinfo"] = strError; } } } catch (Exception ex) { string strErrorText = "Application_Start阶段出现异常: " + ExceptionUtil.GetDebugText(ex); OpacApplication.WriteWindowsLog(strErrorText); if (app != null) { app.GlobalErrorInfo = strErrorText; } else { Application["errorinfo"] = strErrorText; } } }