示例#1
0
        public void ProcessRequest(HttpContext context)
        {
            //context.Response.Write("1");
            //IPage fac=(IPage)Assembly.Load("NewXzc.Web").CreateInstance("NewXzc.Web.Index",true);
            //fac.Page_Load(context);
            #region
            string physicalApplicationPath = context.Request.PhysicalApplicationPath;
            string str4 = context.Request.PhysicalPath.Replace(physicalApplicationPath, string.Empty).Replace("/", ".").Replace(@"\", ".").Replace(".aspx", string.Empty);
            string name = str4.Replace(".", "/") + ".html";
            string str6 = string.Empty;

            //新添加测试
            //if (str4.ToLower() == "default")
            //{
            //    HttpContext.Current.Response.Redirect("/index");
            //    return;
            //}
            //测试结束


            if (str4.ToLower() == "index" || str4.ToLower() == "webscan_360_cn" || str4.ToLower() == "baidu_verify_kyltyss6um")
            {
                str6 = "";
            }
            else
            {
                str6 = "template";
            }
            if (str4.ToLower() == "tools.ueditor.dialogs.image.image")
            {
                str6 = "";
                str4 = "image";
            }
            else if (str4.ToLower() == "tools.ueditor.dialogs.link.link")
            {
                str6 = "";
                str4 = "link";
            }
            else if (str4.ToLower() == "tools.ueditor.dialogs.emotion.emotion")
            {
                str6 = "";
                str4 = "emotion";
            }
            else
            {
                str6 = "template";
            }
            string         str8   = "text/html";
            string         str9   = context.Request.ServerVariables["HTTP_ACCEPT"];
            VelocityEngine engine = new VelocityEngine();
            engine.SetProperty("resource.loader", "file");
            engine.SetProperty("file.resource.loader.path", physicalApplicationPath + str6 + @"\");
            engine.Init();
            VelocityContext ctx             = new VelocityContext();
            string          applicationPath = HttpContext.Current.Request.ApplicationPath;
            if (applicationPath == "/")
            {
                applicationPath = string.Empty;
            }

            #region  获取当前用户的登录状态
            string url_s = HttpContext.Current.Request.Url.ToString().ToLower();

            if (!url_s.Contains("hongrenhui"))
            {
                ctx.Put("headinfo", GetUserLoginState(1));
            }
            else
            {
                ctx.Put("headinfo", GetUserLoginState(1));
            }



            if (!url_s.Contains("userlogin"))
            {
                if (!url_s.Contains("hongrenhui"))
                {
                    //当前用户还未登录
                    if (GetCurUserID_HongRenHui() == 0)
                    {
                        //进入中心页面,直接跳转回登录页
                        if (url_s.Contains("personalcenter"))
                        {
                            HttpContext.Current.Response.Redirect("/login");
                        }
                    }
                }
                else
                {
                    //当前用户还未登录
                    if (GetCurUserID_HongRenHui() == 0)
                    {
                        //进入中心页面,直接跳转回登录页
                        if (url_s.Contains("personalcenter"))
                        {
                            HttpContext.Current.Response.Redirect("/login");
                        }
                    }
                }
            }
            #endregion

            ctx.Put("style", "/template/style");
            ctx.Put("js", "/template/js");
            ctx.Put("img", "/template/img");
            ctx.Put("exname", ".aspx");
            ctx.Put("showimg", NewXzc.Common.ImgHelper.GetCofigShowUrl());
            IHandlerFactory factory = null;
            try
            {
                factory = (IHandlerFactory)Assembly.Load("NewXzc.Web").CreateInstance("NewXzc.Web.templatecs." + str4, true);

                if (factory == null)
                {
                    //name = "/index";
                    name = "/404";
                }
                else if (!(!(context.Request.HttpMethod == "POST")))
                {
                    factory.Page_PostBack(ref ctx);
                }
                else
                {
                    factory.Page_Load(ref ctx);
                }
            }
            catch (Exception ex)
            {
                //context.Response.Redirect("/404");
                context.Response.Write(ex.Message);
            }
            if (ctx.Get("redirecturl") != null)
            {
                string url = ctx.Get("redirecturl").ToString();
                context.Response.Redirect(url);
            }
            try
            {
                Template template = engine.GetTemplate(name);

                StringWriter writer2 = new StringWriter();
                template.Merge(ctx, writer2);
                context.Response.ContentType = str8;
                context.Response.Write(writer2.GetStringBuilder().ToString());
            }
            catch (Exception ex)
            {
                context.Response.Write(ex.Message);
            }
            #endregion
        }