码迷,mamicode.com
首页 > Web开发 > 详细

Kindeditor跨域上传图片在ASP.NET方案中的解决

时间:2016-08-17 22:49:17      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:

虽然标题写的是ASP.NET的解决方案,但是也可用在PHP,Jsp中。直接上代码

首先在客户端中配置

 var editor;
 document.domain = window.location.host;//js解析域
 KindEditor.ready(function (k) {
     editor = k.create(‘#editor_id‘,
       {
                uploadJson: GlobalConfig
                    .RestServiceUrl +
                    "/FileUpload/upload_json.ashx?folder=News&domainhost=" + window.location.host, // ‘upload_json.ashx‘,
                fileManagerJson: GlobalConfig
                    .RestServiceUrl +
                    "/FileUpload/file_manager_json.ashx?folder=News", //‘file_manager_json.ashx‘,
                allowFileManager: true,
                resizeType: 0,
                height: "500px", //编辑器的高度
                urlType: ‘domain‘ //让上传的文件记录绝对路径!
      });

关键代码部分为

document.domain = window.location.host;//js解析域
 public void ProcessRequest(HttpContext context)
    {
        string folder = context.Request["folder"];
        _webhostdomain = context.Request["domainhost"];
        _returnstring = string.Format(@"<script   type=‘text/javascript‘>document.domain = ‘{0}‘</script>",_webhostdomain);
   ....
 context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8");
        context.Response.Write(_returnstring + JsonMapper.ToJson(hash));
        context.Response.End();
}

  类似于jsonp的方式解决

Kindeditor跨域上传图片在ASP.NET方案中的解决

标签:

原文地址:http://www.cnblogs.com/shanligang/p/5782061.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!