【问题标题】:ASP.NET - Open file without showing dialogASP.NET - 打开文件而不显示对话框
【发布时间】:2015-09-08 16:32:33
【问题描述】:

我想在我的 ASP.NET 应用程序中生成一个 ICS 文件 (iCalendar),然后在不显示文件对话框“打开/保存/取消”的情况下自动打开它。

此生成的文件将由用户的默认应用程序打开这些 ics 文件。

我试过这个:

String sICSPath = Server.MapPath(".") + @"\Files\Test.ics";
String sFullText = File.ReadAllText(sICSPath);
sFullText = sFullText.Replace("#NAME#", "MyName");

this.Response.ContentType = "Content-Type: text/Calendar";
this.Response.AddHeader("Cache-Control", "no-cache, must-revalidate");
this.Response.AddHeader("Pragma", "no-cache");
this.Response.AddHeader("Content-Disposition", "inline; filename=calendar.ics");
this.Response.Write(sFullText);
this.Response.End();

我尝试了其他标题,例如 Content-Type : application/outlookContent-Disposition : attachment; 而不是 Content-Disposition : inline; .... 没有成功。

此代码用于通过对话框打开 ICS。但我会自动打开它而不显示此对话框。

如何做到这一点?

【问题讨论】:

    标签: c# asp.net .net icalendar


    【解决方案1】:

    你不能那样做。用户的浏览器设置决定了他们是否会看到保存对话框,或者是否直接保存并打开。

    想象一下,如果它按照您的意愿工作 - 那将是一个巨大的安全漏洞。

    【讨论】:

      猜你喜欢
      • 2010-11-08
      • 2011-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多