博客 (46)

在 ASP.NET Core 或 ASP.NET 5 中部署百度编辑器请跳转此文


本文记录百度编辑器 ASP.NET 版的部署过程,对其它语言版本也有一定的参考价值。

【2020.02.21 重新整理】


下载

从 GitHub 下载最新发布版本:https://github.com/fex-team/ueditor/releases

按编码分有 gbk 和 utf8 两种版本,按服务端编程语言分有 asp、jsp、net、php 四种版本,按需下载。


目录介绍

以 v1.4.3.3 utf8-net 为例,

ueditor 目录结构.png


客户端部署

本例将上述所有目录和文件拷贝到网站目录 /libs/ueditor/ 下。

当然也可以引用 CDN 静态资源,但会遇到诸多跨域问题,不建议。

在内容编辑页面引入:

<script src="/libs/ueditor/ueditor.config.js"></script>
<script src="/libs/ueditor/ueditor.all.min.js"></script>

在内容显示页面引入:

<script src="/libs/ueditor/ueditor.parse.min.js"></script>

如需修改编辑器资源文件根路径,参 ueditor.config.js 文件内顶部文件。(一般不需要单独设置)

如果使用 CDN,那么在初始化 UE 实例的时候应配置 serverUrl 值(即 controller.ashx 所在路径)。


客户端配置

初始化 UE 实例:

var ue = UE.getEditor('tb_content', {
    // serverUrl: '/libs/ueditor/net/controller.ashx', // 指定服务端接收文件路径
    initialFrameWidth: '100%'
});

其它参数见官方文档,或 ueditor.config.js 文件。


服务端部署

net 目录是 ASP.NET 版的服务端程序,用来实现接收上传的文件等功能。

本例中在网站中的位置是 /libs/ueditor/net/。如果改动了位置,那么在初始化 UE 的时候也应该配置 serverUrl 值。

这是一个完整的 VS 项目,可以单独部署为一个网站。其中:

net/config.json  服务端配置文件
net/controller.ashx  文件上传入口
net/App_Code/CrawlerHandler.cs  远程抓图动作
net/App_Code/ListFileManager.cs  文件管理动作
net/App_Code/UploadHandler.cs  上传动作

该目录不需要转换为应用程序。


服务端配置

根据 config.json 中 *PathFormat 的默认配置,一般地,上传的图片会保存在 controller.ashx 文件所在目录(即本例中的 /libs/ueditor/)的 upload 目录中:
/libs/ueditor/upload/image/
原因是 UploadHandler.cs 中 Server.MapPath 的参数是由 *PathFormat 决定的。

修改 config.json 中的 imagePathFormat 为例:

原值:"imagePathFormat": "upload/image/{yyyy}{mm}{dd}/{time}{rand:6}"

改为:"imagePathFormat": "/upload/ueditor/{yyyy}{mm}{dd}/{time}{rand:6}"

以“/”开始的路径在 Server.MapPath 时会定位到网站根目录。

此处不能以“~/”开始,因为最终在客户端显示的图片路径是 imageUrlPrefiximagePathFormat,若其中包含符号“~”就无法正确显示。

在该配置文件中查找所有 PathFormat,按相同的规则修改。


说到客户端的图片路径,我们只要将

原值:"imageUrlPrefix": "/ueditor/net/"

改为:"imageUrlPrefix": ""

即可返回客户端正确的 URL。

当然也要同步修改 scrawlUrlPrefix、snapscreenUrlPrefix、catcherUrlPrefix、videoUrlPrefix、fileUrlPrefix。


特殊情况,在复制包含图片的网页内容的操作中,若图片地址带“?”等符号,会出现无法保存到磁盘的情况,需要修改以下代码:

打开  CrawlerHandler.cs 文件,找到

ServerUrl = PathFormatter.Format(Path.GetFileName(this.SourceUrl), Config.GetString("catcherPathFormat"));

替换成:

ServerUrl = PathFormatter.Format(Path.GetFileName(SourceUrl.Contains("?") ? SourceUrl.Substring(0, SourceUrl.IndexOf("?")) : SourceUrl), Config.GetString("catcherPathFormat"));


如果你将图片保存到第三方图库,那么 imageUrlPrefix 值设为相应的域名即可,如:

改为:"imageUrlPrefix": "//cdn.***.com"

然后在 UploadHandler.cs 文件(用于文件上传)中找到

File.WriteAllBytes(localPath, uploadFileBytes);

在其下方插入上传到第三方图库的代码,以阿里云 OSS 为例:

// 上传到 OSS
client.PutObject(bucketName, savePath.Substring(1), localPath);

在 CrawlerHandler.cs 文件(无程抓图上传)中找到

File.WriteAllBytes(savePath, bytes);

在其下方插入上传到第三方图库的代码,以阿里云 OSS 为例:

// 上传到 OSS
client.PutObject(bucketName, ServerUrl.Substring(1), savePath);


最后有还有两个以 UrlPrefix 结尾的参数名 imageManagerUrlPrefix 和 fileManagerUrlPrefix 分别是用来列出上传目录中的图片和文件的,

对应的操作是在编辑器上的“多图上传”功能的“在线管理”,和“附件”功能的“在线附件”。

最终列出的图片路径是由 imageManagerUrlPrefiximageManagerListPath + 图片 URL 组成的,那么:

"imageManagerListPath": "/upload/ueditor/image",

"imageManagerUrlPrefix": "",

以及:

"fileManagerListPath": "/upload/ueditor/file",

"fileManagerUrlPrefix": "",

即可。

如果是上传到第三方图库的,且图库上的文件与本地副本是一致的,那么将 imageManagerUrlPrefix 和 fileManagerUrlPrefix 设置为图库域名,

服务端仍然以 imageManagerListPath 指定的路径来查找本地文件(非图库),但客户端显示图库的文件 URL。

因此,如果文件仅存放在图库上,本地没有副本的情况就无法使用该功能了。

综上,所有的 *UrlPrefix 应该设为一致。


另外记得配置不希望被远程抓图的域名,参数 catcherLocalDomain


服务端授权

现在来判断一下只有登录用户才允许上传。

首先打开服务端的统一入口文件 controller.ashx

继承类“IHttpHandler”改为“IHttpHandler, System.Web.SessionState.IRequiresSessionState”,即同时继承两个类,以便可使用 Session,
找到“switch”,其上插入:

if (用户未登录) { throw new System.Exception("请登录后再试"); }

即用户已登录或 action 为获取 config 才进入 switch。然后,

else
{
    action = new NotAllowedHandler(context);
}

这里的 NotAllowedHandler 是参照 NotSupportedHandler 创建的,提示语 state 可以是“登录后才能进行此操作。


上传目录权限设置

上传目录(即本例中的 /upload/ueditor/ 目录)应设置允许写入和禁止执行。


基本用法

设置内容:

ue.setContent("Hello world.");

获取内容:

var a = ue.getContent();

更多用法见官方文档:http://fex.baidu.com/ueditor/#api-common


其它事宜

配置上传附件的文件格式

找到文件:config.json,更改“上传文件配置”的 fileAllowFiles 项,

同时在 Web 服务器上允许这些格式的文件可访问权限。以 IIS 为例,在“MIME 类型”模块中添加扩展名。


遇到从客户端(......)中检测到有潜在危险的 Request.Form 值。参考此文


另外,对于不支持上传 .webp 类型的图片的问题,可以作以下修改:
config.json 中搜索“".bmp"”,替换为“".bmp", ".webp"
IIS 中选中对应网站或直接选中服务器名,打开“MIME 类型”,添加,文件扩展名为“.webp”,MIME 类型为“image/webp


最后,为了在内容展示页面看到跟编辑器中相同的效果,请参照官方文档引用 uParse

若有插入代码,再引用:
<link href="/lib/ueditor/utf8-net/third-party/SyntaxHighlighter/shCoreDefault.css" rel="stylesheet" />
<script src="/lib/ueditor/utf8-net/third-party/SyntaxHighlighter/shCore.js"></script>

其它插件雷同。


若对编辑器的尺寸有要求,在初始化时设置即可:

var ue = UE.getEditor('tb_content', {

  initialFrameWidth: '100%',
  initialFrameHeight: 320
});


图片等附件上传到阿里云 OSS 参考此文

xoyozo 10 年前
8,397

版本区别

功能特性 Windows RT Windows 8
(标准版)
Windows8 Pro
(专业版)
Windows 8 Enterprise
(企业版)
与现有Windows 兼容
购买渠道 在设备上预装 大多数渠道 大多数渠道 经过认证的客户
架构 ARM (32-bit) IA-32 (32-bit) or x86-64 (64-bit) IA-32 (32-bit) or x86-64 (64-bit) IA-32 (32-bit) or x86-64 (64-bit)
安全启动
图片密码
开始界面、动态磁帖以及相关效果
触摸键盘、拇指键盘
语言包
更新的资源管理器
标准程序
文件历史
系统的重置功能
Play To “播放至”功能
Connected standby保持网络连接的待机
Windows Update
Windows Defender
增强的多显示屏支持
新的任务管理器
ISO 镜像 and VHD 挂载
移动通信功能
Microsoft 账户
Internet Explorer 10
SmartScreen
Windows 商店
Xbox Live 程序 (包括 Xbox Live Arcade)
Exchange ActiveSync
快速睡眠(snap)
VPN连接
Device encryption
随系统预装的Microsoft Office
桌面 部分
储存空间管理(storage space)
Windows Media Player
Windows Media Center 需另行添加
远程桌面 只作客户端 只作客户端 客户端和服务端 客户端和服务端
从VHD启动
BitLocker and BitLocker To Go
文件系统加密
加入Windows 域
组策略
AppLocker
Hyper-V 仅64bit支持
Windows To Go
DirectAccess
分支缓存(BranchCache)
以RemoteFX提供视觉特效
Metro风格程序的部署

下载地址

根据下面的 SHA1 或文件名在网上搜索下载地址,下载完成后验证其 SHA1 即可。

Windows 8 (x86) - DVD (Chinese-Simplified)
文件名: cn_windows_8_x86_dvd_915414.iso
SHA1: 0C4A168E37E38EFB59E8844353B2535017CBC587


Windows 8 (x64) - DVD (Chinese-Simplified)
文件名: cn_windows_8_x64_dvd_915407.iso
SHA1: A87C4AA85D55CD83BAE9160560D1CB3319DD675C


Windows 8 Pro VL (x86) - DVD (Chinese-Simplified)
文件名: cn_windows_8_pro_vl_x86_dvd_917720.iso
SHA1: EEEF3C3F6F05115C7F7C9C1D19D6A6A6418B5059


Windows 8 Pro VL (x64) - DVD (Chinese-Simplified) 推荐
文件名: cn_windows_8_pro_vl_x64_dvd_917773.iso
SHA1: 9C4EC9FC4FB561F841E22256BC9DEA6D9D6611FF


Windows 8 Enterprise (x86) - DVD (Chinese-Simplified)
文件名: cn_windows_8_enterprise_x86_dvd_917682.iso
SHA1: 951565D8579C5912FB4A407B3B9F715FBDB77EFE


Windows 8 Enterprise (x64) - DVD (Chinese-Simplified)
文件名: cn_windows_8_enterprise_x64_dvd_917570.iso
SHA1: 1280BC3A38A7001FDE981FA2E465DEB341478667

激活方式

目前流行 KMSmicro 激活,写此文时的最新版本是 4.0,下载地址网上搜之(或联系我)。

7,835

设置目录权限
network service

SQL Server 外围应用配置器:
-服务和连接的外围应用配置器
-远程连接
-同时使用 ICP/IP 和 named pipes

SQL Server Management Studio:
-Windows 身份验证 登录
-本机服务器右键属性
-安全性 改验证模式
-登录名 可用sa,可新建 状态 设置登录启用

6,606

本文所述部署 DotNetTextBox 的版本为:免费开源版 3.4.1,仅供参考!

引用dll:

ActiproSoftware.CodeHighlighter.Net20.dll
ActiproSoftware.Shared.Net20.dll
CodeHighlighterTest.dll
DotNetTextBox.dll
EnvDTE.dll
Interop.Word.dll
Microsoft.Vbe.Interop.dll
Office.dll
Word_dntb.dll

调用方法:

1.直接在ASPX页面引用控件的话,请将 DotNetTextBox.dll 复制到页面所在项目的 bin 目录下,并在web.config 的 pages -> controls 节点加:

<add tagPrefix="DNTB" namespace="DotNetTextBox" assembly="DotNetTextBox"/>

在需要加入控件的地方添加:

<DNTB:WebEditor ID="WebEditor1" runat="server" systemFolder="system_dntb/" Skin="skin/XP/" PathType="AbsoluteRoot" />

上面设置了我默认的属性。

2.将默认属性写在 appSettings 里,可以不做。

3.添加控件到VS的工具箱,可以不做。

4.将 system_dntb 目录拷贝到所在项目里。

5.将控件 bin 目录里的 ActiproSoftware.CodeHighlighter.Net20.dll、ActiproSoftware.Shared.Net20.dll、CodeHighlighterTest.dll 拷贝到项目 BIN 目录里(如果不需要代码高亮功能,删除 system_dntb 目录里的 PasteCode.aspx 和 PasteCode.aspx.cs 页面就可以不拷贝这三个 DLL 文件)

6.web.config 中设置 codeHighlighter
configSections中加入:

<section name="codeHighlighter" requirePermission="false" type="ActiproSoftware.CodeHighlighter.CodeHighlighterConfigurationSectionHandler, ActiproSoftware.CodeHighlighter.Net20"/>

加入以下代码为二级节点:

<codeHighlighter>
<cache languageTimeout="3"/>
<keywordLinking enabled="true" target="_blank" defaultKeywordCollectionKey="ActiproKeywords">
<keywordCollection key="ActiproKeywords">
<explicitKeyword tokenKey="IdentifierToken" patternValue="Actipro" url="http://www.actiprosoftware.com" caseSensitive="false"/>
<explicitKeyword tokenKey="IdentifierToken" patternValue="CodeHighlighter" url="http://www.codehighlighter.com" caseSensitive="false"/>
</keywordCollection>
</keywordLinking>
<languages>
<language key="Assembly" definitionPath="~/system_dntb/Lexers/ActiproSoftware.Assembly.xml"/>
<language key="BatchFile" definitionPath="~/system_dntb/Lexers/ActiproSoftware.BatchFile.xml"/>
<language key="C#" definitionPath="~/system_dntb/Lexers/ActiproSoftware.CSharp.xml"/>
<language key="CSS" definitionPath="~/system_dntb/Lexers/ActiproSoftware.CSS.xml"/>
<language key="HTML" definitionPath="~/system_dntb/Lexers/ActiproSoftware.HTML.xml"/>
<language key="INIFile" definitionPath="~/system_dntb/Lexers/ActiproSoftware.INIFile.xml"/>
<language key="Java" definitionPath="~/system_dntb/Lexers/ActiproSoftware.Java.xml"/>
<language key="JScript" definitionPath="~/system_dntb/Lexers/ActiproSoftware.JScript.xml"/>
<language key="Lua" definitionPath="~/system_dntb/Lexers/ActiproSoftware.Lua.xml"/>
<language key="MSIL" definitionPath="~/system_dntb/Lexers/ActiproSoftware.MSIL.xml"/>
<language key="Pascal" definitionPath="~/system_dntb/Lexers/ActiproSoftware.Pascal.xml"/>
<language key="Perl" definitionPath="~/system_dntb/Lexers/ActiproSoftware.Perl.xml"/>
<language key="PHP" definitionPath="~/system_dntb/Lexers/ActiproSoftware.PHP.xml"/>
<language key="PowerShell" definitionPath="~/system_dntb/Lexers/ActiproSoftware.PowerShell.xml"/>
<language key="Python" definitionPath="~/system_dntb/Lexers/ActiproSoftware.Python.xml"/>
<language key="SQL" definitionPath="~/system_dntb/Lexers/ActiproSoftware.SQL.xml"/>
<language key="VB.NET" definitionPath="~/system_dntb/Lexers/ActiproSoftware.VBDotNet.xml"/>
<language key="VBScript" definitionPath="~/system_dntb/Lexers/ActiproSoftware.VBScript.xml"/>
<language key="XAML" definitionPath="~/system_dntb/Lexers/ActiproSoftware.XAML.xml"/>
<language key="XML" definitionPath="~/system_dntb/Lexers/ActiproSoftware.XML.xml"/>
</languages>
<lineNumberMargin foreColor="Teal" paddingCharacter=" " visible="true"/>
<outlining enabled="true" imagesPath="~/system_dntb/OutliningIndicators/"/>
<spacesInTabs count="4"/>
</codeHighlighter>

7.在使用的页面需要设置page: ValidateRequest="false" EnableEventValidation="false"

8.搜索 id 为 OutliningEnabledCheckBox 的单选框,更改默认 Checked="true",显示行号也可以改为选中,不过这样不方便读者复制代码使用。

另外提醒一点,DotNetTextBox 在 UpdatePanel 中使用时,回传后会丢失内容,使用时注意。

7,338

下载最新的免费CodeHighlighter组件 http://www.CodeHighlighter.com

1。确保web.config中的languages节点的.xml文件路径正确。
2。可以在insertCode.aspx更改编辑的默认设置,如checkbox的check等。(或在项目中搜索相关代码)

 


 

 

 

DotNetTextBox 已集成CodeHighlighter,我的修改如下:

xoyozo 18 年前
6,870

代码:

<input type="text" name="re_name" style="width: 100px; height: 21px; font-size: 10pt;" /><span
style="width: 18px; border: 0px solid red;">
<select name="r00" style="margin-left: -101px; width: 118px; background-color: #FFEEEE;"
onchange="document.all.re_name.value=this.value;">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</span>

 

说明:

该代码兼容性非常差,在XHTML文档中或在非IE浏览下浏览均不能达到预期效果,原因可能是它们的 select 元素的 z-index 太高,并且 css 定位方式不同,部署于应用还需改进代码。

xoyozo 18 年前
6,945