如何在提供下载之前设置文件readonly [英] how to set file readonly before it provide to download

查看:68
本文介绍了如何在提供下载之前设置文件readonly的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Response.ContentType = "Application/pdf";
    Response.AppendHeader("Content-Disposition", "attachment; filename=HT_2_hallticket.pdf");
    Response.TransmitFile(Server.MapPath("~/QuestionBank/Malabar College of Engineering And Technology/HT_2_hallticket.pdf"));
    Response.End();

推荐答案

这是一个基本的东西:Web应用程序无法控制客户端系统。从这些应用程序的角度来看,客户端系统甚至不必拥有文件系统。 Web应用程序只提供某些内容文件的文件内容。 保存文件是浏览器的功能。浏览器会做它的功能;你甚至不知道在客户端使用哪种浏览器。



因此,你不仅无法控制文件属性,而且严格来说,对于服务器端这个客户端文件甚至不作为概念存在;这个问题毫无意义。



现在,让我们来看看实际方面:什么能让你的文件只读?真的没什么。首先,很多软件可以简单地忽略这个标志。当然,您无法对文件权限执行任何操作,这需要权限提升。服务器端的文件(如果有文件)在所有情况下都将保持不变。这就是最重要的。如果用户丢失了文件,可以再次下载。



最后,如果您的目标是保持文件不可修改,请将其保持为只读只是不严肃。对于这样的事情,存在数字签名。



-SA
Here is one fundamental thing: a Web application does not have control over the client systems. From the standpoint of such applications, the client system is not even obliged to have a file system. The Web application simply provides file content of certain content file. "Saving a file" is a functionality of a browser. And a browser does what it does; you don't even know which browser is used on the client side.

So, not only you have no control over the file attributes, but, strictly speaking, for the server side this client-side file does not even exist as a notion; that is the question makes no sense.

Now, let's look at the practical aspect: what can give you having a file read-only? Nothing, really. First, a lot of software can simply ignore this flag. And of course you cannot do anything with file permissions, which would need privilege elevation. The file on the server side (if there is a file) will remain intact in all cases. This is all what matters. If a user looses the file, it can be downloaded again.

And, finally, if your goal is to keep the file non-modifiable, keeping it read-only is just not serious. For such things, digital signature exists.

—SA


您需要了解问题首先。



因此,首先分析要求。当你这么说时,文件将是只读的,那么文件的目的是什么。为什么用户会下载?存在哪些是合理的,如果用户编辑和提交,那么它会产生问题与否。所以,在实现之前先想想。
You need to understand the problem first.

So, analyze the requirement first. When you say that, file will be read only, then what is the purpose of the file. Why user would download that? Is there something exists which is sensible and if user edits and submits, then it would create problems or not. So, think before implementing.


会员11026295写道:
Member 11026295 wrote:

我不想复制我的pdf文件也。

I don't want to copy my pdf file also.

对不起,它现在取决于你想要的。它只是暗示你不知道Web通常会做什么,否则你会意识到这个非常基本的事情:如果某些内容可以在客户端查看,则已经下载了。想要什么东西太迟了。 :-)



此外,在实际操作中,PDF内容不仅会在此时下载,还会保存在客户端计算机上的某个文件中。即使用户没有使用另存为,即使PDF在浏览器中呈现。顺便说一句,所有系统和浏览器都不支持在浏览器中呈现,不应该假设。任何非废话的用户都可以拥有这个文件,只需面对它。



-SA

Sorry, it does now depend on what you want. It simply suggests you have no idea what the Web does in general, otherwise you would realize this very basic thing: if some content can be looked through on a client side, it is already downloaded. Too late to want something. :-)

Moreover, in real practice, the PDF content is not only downloaded by this moment, but also saved in some file on the client computer. Even if the user did not use "Save As", even if the PDF is rendered in the browser. By the way, rendering in the browsers is not supported by all systems and browsers and should not be assumed. Any non-nonsense user can have this file, just face it.

—SA


这篇关于如何在提供下载之前设置文件readonly的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆