随笔 - 165, 文章 - 0, 评论 - 18, 阅读 - 22万
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

.net core 6中使用UEditor记录

Posted on   火冰·瓶  阅读(268)  评论(0编辑  收藏  举报

1.在NuGet中添加包:UEditor.Core

或通过程序包管理控制台:Install-Package UEditor.Core

 

 2.添加服务端统一请求接口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class UEditorController : Controller
{
    private readonly UEditorService _ueditorService;
    public UEditorController(UEditorService ueditorService)
    {
        this._ueditorService = ueditorService;
    }
 
    [HttpGet, HttpPost]
    public ContentResult Upload()
    {
        var response = _ueditorService.UploadAndGetResponse(HttpContext);
        return Content(response.Result, response.ContentType);
    }
}

 

3.在Program.cs中添加

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//代码一
builder.Services.AddUEditorService();
 
 
//代码二
app.UseStaticFiles(new StaticFileOptions
{
    FileProvider = new PhysicalFileProvider(
       Path.Combine(Directory.GetCurrentDirectory(), "upload")),
    RequestPath = "/upload",
    OnPrepareResponse = ctx =>
    {
        ctx.Context.Response.Headers.Append("Cache-Control", "public,max-age=36000");
    }
});

 

4.在项目跟路径下添加两个文件夹  

  

 

5.复制UEditor静态资源包到wwwroot/lib目录下

 

6.复制配置文件到项目根目录

把\wwwroot\lib\ueditor1_4_3_3\net\config.json  复制到根目录并改名为:ueditor.json 

 

 7.修改根目录下的ueditor.json中的配置

修改ueditor.json中的上传图片和文件路径

修改前:

 修改后:

 共有8处需要修改

 

8.修改ueditor.config.js文件中的服务端统一请求接口路径

文件在这个位置:\wwwroot\lib\ueditor1_4_3_3\ueditor.config.js

  

9.在需要使用UEditor的页面添加如下代码

1
2
3
4
5
6
7
8
9
10
11
<script src="~/lib/ueditor1_4_3_3/ueditor.config.js"></script>
<script src="~/lib/ueditor1_4_3_3/ueditor.all.min.js"></script>
 
 
<div id="container"></div>
 
<script type="text/javascript">
    var ue = UE.getEditor('container', {
        initialFrameHeight: 500
    });
</script>

 

10.修改控件中加载百度地图时出错问题  

修改如下2个静态页面

\wwwroot\lib\ueditor1_4_3_3\dialogs\map\map.html

\wwwroot\lib\ueditor1_4_3_3\dialogs\map\show.html

把老版的百度地图接口js引用替换成新版的,并加上自己申请的ak

修改获取标注坐标的方法

var point = marker.getPosition();

修改加载百度静态图url为新版

var url = "https://api.map.baidu.com/staticimage/v2?ak=AK&mcode=666666&center=" + point.lng + "," + point.lat + "&width=" + size.width + "&height=" + size.height + "&zoom=" + zoom;

 

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示