0

出于安全原因,当用户单击查看本地 html 文件的子类 WebBrowser 中的弹出窗口时,我试图禁用 Outlook(或任何默认邮件客户端)的打开。我尝试用没有“mailto:”链接引用的版本替换 DocumentText,但这一直失败(无论我尝试什么,它在设置 DocumentText 后一直坚持 about:blank 页面)。

我的问题的最佳解决方案是通过注册表或其他方式完全禁用任何默认邮件客户端,但我对任何我还没有尝试过的东西持开放态度。有任何想法吗?

4

1 回答 1

0

我能够通过覆盖 html 文件以不包含“mailto”引用来解决我的安全问题。文件被替换后,我简单地刷新了一下:

  TextReader tr = File.OpenText(e.Url.LocalPath);
  htmlFile = tr.ReadToEnd();
  tr.Close();
  tr.Dispose();

  if (htmlFile.Contains("mailto:support@website.com"))
  {
      htmlFile = htmlFile.Replace("mailto:support@website.com", @"about:blank");

      //Recreate new file with fixed html
      File.Delete(e.Url.LocalPath);
      TextWriter tw = File.CreateText(e.Url.LocalPath);
      tw.Write(htmlFile);
      tw.Flush();
      tw.Close();
      tw.Dispose();

      Refresh();
  }
于 2011-04-19T22:25:05.943 回答