KindEditor 批量图片上传cookie问题

后台

protected void Application_BeginRequest(object sender, EventArgs e)
        {
            /* we guess at this point session is not already retrieved by application so we recreate cookie with the session id... */
            try
            {
                string session_param_name = "ASPSESSID";
                string session_cookie_name = "ASP.NET_SessionId";

                if (HttpContext.Current.Request.Form[session_param_name] != null)
                {
                    UpdateCookie(session_cookie_name, HttpContext.Current.Request.Form[session_param_name]);
                }
                else if (HttpContext.Current.Request.QueryString[session_param_name] != null)
                {
                    UpdateCookie(session_cookie_name, HttpContext.Current.Request.QueryString[session_param_name]);
                }
            }
            catch
            {
            }

            try
            {
                string auth_param_name = "AUTHID";
                string auth_cookie_name = System.Web.Security.FormsAuthentication.FormsCookieName;

                if (HttpContext.Current.Request.Form[auth_param_name] != null)
                {
                    UpdateCookie(auth_cookie_name, HttpContext.Current.Request.Form[auth_param_name]);
                }
                else if (HttpContext.Current.Request.QueryString[auth_param_name] != null)
                {
                    UpdateCookie(auth_cookie_name, HttpContext.Current.Request.QueryString[auth_param_name]);
                }

            }
            catch
            {
            }
        }

        private void UpdateCookie(string cookie_name, string cookie_value)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies.Get(cookie_name);
            if (null == cookie)
            {
                cookie = new HttpCookie(cookie_name);
            }
            cookie.Value = cookie_value;
            HttpContext.Current.Request.Cookies.Set(cookie);
        }

前台

var auth = "@(Request.Cookies[FormsAuthentication.FormsCookieName]==null ? string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value)";
        var ASPSESSID = "@Session.SessionID";
var editor;
        KindEditor.ready(function (K) {
            editor = K.create('#Description', {
                cssPath: '../../Content/kindeditor-4.1.7/plugins/code/prettify.css',
                uploadJson: '../../Content/kindeditor-4.1.7/asp.net/upload_json.ashx',
                fileManagerJson: '../../Content/kindeditor-4.1.7/asp.net/file_manager_json.ashx',
                allowFileManager: true,
                resizeMode: 0,
                extraFileUploadParams: { 'ASPSESSID': '@ASPSESSID', 'AUTHID': '@auth' }
        });
        });

 

posted @ 2016-01-14 11:36  zolz  阅读(416)  评论(1)    收藏  举报