我找到了一個解決方案,使用Render()方法將URL路徑替換爲正確的路徑。此forum post有關於此解決方案的信息。我將不得不對其進行修改以檢查Request.Url以查看頁面請求來自哪個域。
protected override void Render(HtmlTextWriter writer)
{
try
{
StringBuilder renderedOutput = new StringBuilder();
StringWriter strWriter = new StringWriter(renderedOutput);
HtmlTextWriter tWriter = new HtmlTextWriter(strWriter);
base.Render(tWriter);
//this string is to be searched for src="/" mce_src="/" and replace it with correct src="./" mce_src="./".
string s = renderedOutput.ToString();
s = Regex.Replace(s, "(?<=<img[^>]*)(src=\\\"/)", "src=\"./", RegexOptions.IgnoreCase);
s = Regex.Replace(s, "(?<=<script[^>]*)(src=\\\"/)", "src=\"./", RegexOptions.IgnoreCase);
s = Regex.Replace(s, "(?<=<a[^>]*)(href=\\\"/)", "href=\"./", RegexOptions.IgnoreCase);
writer.Write(s);
}
catch
{
}
}
}