[英]HTTP Handler Restricting Files to be only Readonly / View Only instead of Downloadable C# ASP.NET WebPage
我有一个带有联机文件库的客户端。 她希望能够在表单库“ ReadOnly”中制作一些文件。
现在,当您查看文件库页面时,将显示所有文件。
当您单击文件时,它将打开标准浏览器窗口,并询问您是否要打开或下载文件。 基本上,她希望限制某些文件以仅允许您打开而不下载文件。
我很确定这是不可能的,因为这是用户偏好浏览器设置类型的事情,但我认为在告诉她之前我会得到一些输入。
现在我正在使用我编写的称为文件处理程序的asp.net HTTP处理程序。
public void ProcessRequest(HttpContext context)
{
if (this.FileName != null)
{
string path = String.Concat(ConfigurationManager.UploadsDirectory, this.FileName);
string contentType = Utility.IO.File.GetContentType(this.FileName);
if (File.Exists(path) == true)
{
context.Response.Buffer = true;
context.Response.Clear();
context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
context.Response.ContentType = contentType;
context.Response.AddHeader("content-disposition", String.Format("inline; filename={0}", (Url.Encode(this.DisplayFileName))));
context.Response.TransmitFile(path);
context.Response.Flush();
context.Response.End();
}
else
{
throw new HttpException(404, "File Not Found");
}
}
}
此函数(Utility.IO.File.GetContentType)是一个简单的实用程序函数,用于基于文件扩展名获取内容类型。
无论如何,我可以在此代码中进行任何更改以使其变为只读文件或“仅查看”文件。 也许我可以添加某种类型的标题?
回答我自己的问题。 这是不可能的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.