Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个包含文本文件列表的网页(使用 ASP.NET 构建)。我希望用户能够单击文件并使用默认文本编辑器打开它。
预计用户已经拥有相关文件,我真的只需要打开它。
编辑:目前只需要支持 Windows & Firefox & Chrome。
我认为你能做的最好的事情是使用 Response.ContentType 强制文件作为下载,如下所示:
Response.ContentType = "text/plain"; Response.AppendHeader("content-disposition", "attachment; filename=" + fileName);
如果您将文件的内容直接通过管道传输到响应流(从而强制下载),它将提示用户保存或在文本编辑器中打开文件。我认为这是您在不发明自己的协议的情况下将获得的最接近的结果。