第一步:官方下载ueditor
第二步:在Nuget中搜索UEditor.Core并安装
第三步:修改Program.cs添加以下代码,原来的app.UseStaticFiles();不要删除。
builder.Services.AddSession(); 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"); } });
第四步:创建一个UEditorController,并添加如下代码:
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); } }
第五步:将ueditor net文件后端的config.json 改名 为ueditor.json添加到项目根目录
第六步:打开ueditor.config.js文件,将其中的serverUrl项改为:/ueditor/upload
第七步:修改ueditor.json代码中的图片路径
"imageUrlPrefix": "/", /* 图片访问路径前缀 */ "imagePathFormat": "upload/image/{yyyy}{mm}{dd}/{time}{rand:6}",
然后就可以像在ASP.NET页面中那样使用ueditor。