RichTextBox 在本地服务器上工作但不在 Azure Web API 服务器上工作

RichTextBox working in local server but not on Azure Web API Server

我正在使用 RichTextBox 将从休息服务接收的 RTF 文本转换为纯文本。

我已经使用了这个MSDN

中推荐的代码

同样在本地机器 IISExpress 服务器上工作,其中文本被转换为纯文本。但是,一旦部署在 Azure App Service(Web API) 上,我就会毫无例外地收到空白响应。

在服务器上发布代码时,我已确保 System.Windows.Forms.dll 存在于我的 bin 文件夹中。

负责将文本转换为纯文本的代码。

try {
 RichTextBox rtBox = new RichTextBox();
 rtBox.Rtf = cm.Message;
 cm.Message = rtBox.Text;
} catch(Exception ex) {
 System.Diagnostics.Trace.TraceError("Error when RTF ::" + ex.StackTrace);
}   

这是我要转换的 RTF 文本:

{\rtf1\ansi\ansicpg1252\deff0\deflang2057{\fonttbl{\f0\fnil\fcharset0 EK03Plain-L01;}{\f1\fnil Courier New;}}{\colortbl ;\red0\green0\blue128;\red0\green0\blue0;}\viewkind4\uc1\pard\cf1\b\f0\fs20  \cf2   Sample Text 1\parSample Test 2\b0\f1\par\cf1\par}

当 运行 此代码在我的本地计算机上时:我得到以下预期输出:

Sample Text 1 \nSample Test 2

但在 Azure 上它只是 return 空白响应。即“”

System.Windows.Forms.dll 包含很多 UI 代码,这些代码很可能无法在 Azure 网站沙箱中运行。关于azure web app sandbox的更多细节,请参考here.

还有一个不使用 System.Windows.Forms.dll 的解决方法,看看这个 answer