Beispiel #1
0
        public static bool PrepareEnvironment(Page page,
                                              ref OpacApplication app,
                                              ref SessionInfo sessioninfo)
        {
            string strErrorInfo = "";

            // 获得app对象
            // 并检查系统错误字符串

            // 2008/6/6
            // 错误信息采用两级存放策略。
            // 如果LibraryAppliation对象已经存在,则采用其ErrorInfo成员的值;
            // 否则,采用Application["errorinfo"]值
            app = (OpacApplication)page.Application["app"];
            if (app == null)
            {
                strErrorInfo = (string)page.Application["errorinfo"];

                if (String.IsNullOrEmpty(strErrorInfo) == true)
                {
                    strErrorInfo = "app == null";
                }

                page.Response.Write(HttpUtility.HtmlEncode(strErrorInfo).Replace("\r\n", "<br/>"));
                page.Response.End();
                return(false);
            }
            else
            {
                strErrorInfo = app.GlobalErrorInfo;
                if (String.IsNullOrEmpty(strErrorInfo) == false)
                {
                    page.Response.Write(HttpUtility.HtmlEncode(strErrorInfo).Replace("\r\n", "<br/>"));
                    page.Response.End();
                    return(false);
                }

                if (app.XmlLoaded == false)
                {
                    strErrorInfo =
                        "<html><body><pre>" +
                        HttpUtility.HtmlEncode("OPAC 初始化时装载 XmlDefs 失败,可能的原因是:OPAC 所依赖的 dp2Library 服务模块尚未启动,或 OPAC 代理帐户不存在、权限不够或密码被修改...。\r\n具体出错原因请察看 dp2OPAC 数据目录 log 子目录下的当日日志文件(log_????????.txt),并及时排除故障。OPAC 系统将在稍后自动重试装载 XmlDefs。");
                    page.Response.Write(strErrorInfo);

                    if (page.Request.UserHostAddress == "localhost" ||
                        page.Request.UserHostAddress == "::1")
                    {
                        page.Response.Write("\r\n\r\n");
                        // 输出当天日志文件内容
                        app.DumpErrorLog(page);
                    }

                    page.Response.Write("</pre></body></html>");
                    page.Response.End();
                    return(false);
                }
            }

            /*
             * string strErrorInfo = (string)page.Application["errorinfo"];
             *
             * if (String.IsNullOrEmpty(strErrorInfo) == false)
             * {
             *  page.Response.Write(HttpUtility.HtmlEncode(strErrorInfo).Replace("\r\n","<br/>"));
             *  page.Response.End();
             *  return false;   // error
             * }*/

            // 获得SessionInfo
            sessioninfo = (SessionInfo)page.Session["sessioninfo"];
            if (sessioninfo == null)
            {
                /*
                 * strErrorInfo = "sessioninfo == null";
                 * page.Response.Write(strErrorInfo);
                 * page.Response.End();
                 * return false;
                 * */

                // 2013/12/7
                string strClientIP = HttpContext.Current.Request.UserHostAddress.ToString();
                // 增量计数
                if (app != null)
                {
                    long v = app.IpTable.IncIpCount(strClientIP, 1);
                    if (v >= app.IpTable.MAX_SESSIONS_PER_IP)
                    {
                        app.IpTable.IncIpCount(strClientIP, -1);
                        strErrorInfo             = "同一 IP 前端数量超过配额 " + app.IpTable.MAX_SESSIONS_PER_IP.ToString() + "。请稍后再试。";
                        page.Response.StatusCode = 403;
                        // page.Response.StatusDescription = strErrorInfo;
                        page.Response.Write(strErrorInfo);
                        page.Response.End();
                        // TODO: 也可以 redirect 引导到一个说明性的页面
                        return(false);
                    }
                }

                try
                {
                    sessioninfo                 = new SessionInfo(app);
                    sessioninfo.ClientIP        = strClientIP;
                    page.Session["sessioninfo"] = sessioninfo;
                }
                catch (Exception ex)
                {
                    strErrorInfo = "PrepareEnvironment()创建Session出现异常: " + ExceptionUtil.GetDebugText(ex);
                    page.Response.Write(strErrorInfo);
                    page.Response.End();
                    return(false);
                }
            }

            string strLang = (string)page.Session["lang"];

            sessioninfo.ChannelLang = strLang;

            if (page is MyWebPage)
            {
                (page as MyWebPage).LoadCookiesLoginToSession();
            }

            return(true);
        }