Winforms WebControl - 如何防止链接转义?

时间:2014-12-10 19:27:42

标签: c# html winforms escaping asp.net-webcontrol

我正在使用WebControl作为WYSIWYG编辑器在Winforms .NET 4.0项目中开发 - 使用Matt Groves开发的YARTE editor

我正在尝试添加锚标记并将href属性设置为以下路径:

var path = http://someurl.aspx?param1="val1"&param2="val2"&param3="youGetTheIdea"

我尝试了几种方法;当我尝试将url写入文档时,我总是得到HTML转义的&符号:

http://someurl.aspx?param1="this"&param2="doesnt"&param3="work"

我尝试过的尝试不成功:

  1. 创建链接

    webBrowser.ExecCommand("CreateLink", false, path)
    
  2. 创建HTML并将其粘贴到:

    var htmlDocument2 = args.Document.DomDocument as IHTMLDocument2;
    if (htmlDocument2 == null) return;
    var range = htmlDocument2.selection.createRange() as IHTMLTxtRange;
    if (range == null) return;
    range.pasteHTML(string.Format(path, range.text));
    
  3. 创建文件并将webBrowser指向它:

    // assume the links are already inserted, but aren't right.
    var textWithBadLinks = webBrowser.DocumentText;
    var betterText = UseRegexToReplaceBadLinkText(textWithBadLinks);
    using (StreamWriter outfile =new StreamWriter(@"c:\test.html"))
    {
      outfile.Write(betterText);
    }
    webBrowser.Url= new Uri(@"c:\test.html");
    
  4. 创建流并将webBrowser指向它:

    // same as above, but instead of the URL, use the DocumentStream:
    webBrowser.DocumentStream = new StreamWriter(@c:\test.html);
    
  5. 导航到文件:

    webBrowser.Navigate(new Uri(@"c:\test.html"))
    
  6. 无论我选择什么方法,&符号都会逃脱链接无法正常工作。

    提前感谢你的帮助。

1 个答案:

答案 0 :(得分:1)

从技术上讲,XHTML要求& amp有效。请参阅:XHTML and & (Ampersand) encoding