Ejemplo n.º 1
0
        public ExportHelper(bool isexport, int?pageSize, string filename, JContext jc)
        {
            this.isexport = isexport;

            if (!filename.EndsWith(".xls") || !filename.EndsWith(".xlsx"))
            {
                this.filename = filename + ".xls";
            }
            else
            {
                this.filename = filename;
            }

            this.jc = jc;

            QC = new WebQuery();
            QC.LoadCondidtion();

            if (this.isexport)
            {
                if (jc.QueryString["export"] == "all")
                {
                    QC.NoPaging();
                }
                else if (pageSize != null)
                {
                    QC.PageSize = pageSize.Value;
                }
            }
            else
            {
                QC.PageSize = pageSize.Value;
            }
        }
        public override bool IsAuthorized(Principal user)
        {
            JContext jc = JContext.Current;

            if (!Independent && !jc.Context.Items["_has_controlpanel_permission_"].ToBoolean())
            {
                return(false);
            }

            IArea area = jc.Area;

            string per = Permission;

            if (area["support_multi_site"].ToBoolean())
            {
                per = string.Format("{0}@{1}", per, jc.SiteId);
            }

            if (user != null && StringUtil.HasText(per))
            {
                return(user.HasPermission(per));
            }

            return(true);
        }
Ejemplo n.º 3
0
        private void onBeginRequest(object sender, EventArgs e)
        {
            if (EventBroker.IsStaticResource((sender as HttpApplication).Request))
            {
                return;
            }

            JContext jc = JContext.Current;

            if (jc == null)
            {
                return;
            }

            HttpContext context = jc.Context;

            if (context.Request.Url.AbsolutePath.IndexOf("_res.aspx", StringComparison.InvariantCultureIgnoreCase) != -1 ||
                context.Request.Url.AbsolutePath.IndexOf("_resc.aspx", StringComparison.InvariantCultureIgnoreCase) != -1)
            {
                return;
            }

            if (jc.Area != null)
            {
                context.Items["SITE_KEY"] = jc.Area.AreaKey;
            }

            if (!context.Response.IsRequestBeingRedirected)
            {
                context.Response.AddHeader("X-Powered-By", "TXTEK");
            }

            context.Items["_PAGE_ID_"] = StringUtil.UniqueId();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a Context instance based on HttpContext. Generally, this
        /// method should be called via Begin_Request in an HttpModule
        /// </summary>
        public static JContext Create(HttpContext context)
        {
            JContext jcontext = new JContext(context, true);

            SaveContextToStore(jcontext);

            return(jcontext);
        }
Ejemplo n.º 5
0
 private static void SaveContextToStore(JContext context)
 {
     if (context.Context != null)
     {
         context.Context.Items[dataKey] = context;
     }
     else
     {
         Thread.SetData(GetSlot(), context);
     }
 }
Ejemplo n.º 6
0
 public ExportHelper(int?pageSize, string filename, JContext jc)
     : this(StringUtil.HasText(jc.QueryString["export"]), pageSize, filename, jc)
 {
 }
Ejemplo n.º 7
0
 public ExportHelper(string filename, JContext jc)
     : this(10, filename, jc)
 {
 }
Ejemplo n.º 8
0
        public string GetRealThemeName(IArea area)
        {
            JContext jc = JContext.Current;

            return(GetRealThemeName(area, area.Theme));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 依赖的资源名称,多个资源名称使用逗号分隔
        /// </summary>
        /// <param name="resourceName"></param>
        public void Require(IArea area, string resourceName)
        {
            if (string.IsNullOrEmpty(resourceName))
            {
                return;
            }

            JContext jc = JContext.Current;

            foreach (var res in StringUtil.Split(resourceName, StringUtil.Comma, true, true))
            {
                if (res == "jquery.js")
                {
                    Head.RequireJquery = true;
                    continue;
                }

                string resourceUrl = string.Empty;

                string key = string.Format("define_{0}", res);

                if (area != null && !string.IsNullOrEmpty(area[key]))
                {
                    resourceUrl = jc.CombinUrl(area, area[key], false);
                }
                else
                {
                    foreach (IArea item in jc.Host.AllAreas)
                    {
                        if (area != null && item.AreaKey == area.AreaKey)
                        {
                            continue;
                        }

                        if (!string.IsNullOrEmpty(item[key]))
                        {
                            resourceUrl = jc.CombinUrl(item, item[key], false);
                            break;
                        }
                    }

                    if (string.IsNullOrEmpty(resourceUrl))
                    {
                        if (res == "kiss.js" || res == "kiss.css" || res == "jqueryui.js" || res == "jqueryui.css")
                        {
                            resourceUrl = Resources.Utility.GetResourceUrl(GetType(), "Kiss.Web.jQuery." + res, true);
                        }
                        else
                        {
                            throw new WebException("未找到{0}的定义。", res);
                        }
                    }
                }

                if (res.EndsWith(".js"))
                {
                    RegisterJs(resourceUrl);
                }
                else if (res.EndsWith(".css"))
                {
                    RegisterCss(resourceUrl);
                }
            }
        }
Ejemplo n.º 10
0
        public void Notify(Exception ex)
        {
            if (ex is HttpUnhandledException)
            {
                ex = ex.InnerException;
            }

            if (ex == null)
            {
                return;
            }

            logger.Error(HttpContext.Current.Request.RawUrl + ExceptionUtil.WriteException(ex));

            OnNotifyError(new NotifyErrorEventArgs()
            {
                Exception = ex
            });

            int statusCode = HttpContext.Current.Response.StatusCode;

            while (ex != null)
            {
                if (ex is HttpException)
                {
                    statusCode = (ex as HttpException).GetHttpCode();

                    break;
                }

                ex = ex.InnerException;
            }

            HttpContext.Current.Response.Clear();

            JContext jc = JContext.Current;

            HttpContext.Current.Response.StatusCode      = 200;
            HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;

            if (!File.Exists(HttpContext.Current.Server.MapPath("~/error.htm")))
            {
                logger.Warn("未找到error.htm文件。");

                if (jc.IsAjaxRequest)
                {
                    HttpContext.Current.Response.Write(new Kiss.Json.JavaScriptSerializer().Serialize(new AjaxServerException()
                    {
                        Action    = AjaxServerExceptionAction.JSEval,
                        Parameter = "alert('您的访问出错了')"
                    }.ToJson()));
                }
                else
                {
                    HttpContext.Current.Response.Write("<h1>:(</h1>您的访问出错了");
                }
            }
            else
            {
                string error_pageUrl = jc.url("~error.htm?code=" + statusCode);

                if (jc.IsAjaxRequest)
                {
                    HttpContext.Current.Response.Write(new Kiss.Json.JavaScriptSerializer().Serialize(new AjaxServerException()
                    {
                        Action    = AjaxServerExceptionAction.JSEval,
                        Parameter = string.Format("window.location='{0}'", error_pageUrl)
                    }.ToJson()));
                }
                else
                {
                    HttpContext.Current.Response.Redirect(error_pageUrl);
                }
            }

            HttpContext.Current.Response.End();
        }