使用ASP.Net打开以只读模式对用户可见的.txt文件 [英] Open a .txt file which is visible to user in ReadOnly mode using ASP.Net

查看:77
本文介绍了使用ASP.Net打开以只读模式对用户可见的.txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个.aspx页面,在其中单击按钮时,我想在ReadOnly Mode中打开一个.txt文件.打开的文件仅对用户可见.用户无法编辑文件,并且用户无法对其执行保存操作.

Hi,

I have a .aspx page where in on Button Click, I want to open a .txt file in ReadOnly Mode. Opened file will only be visible to user. User cannot edit the file and User cannot perform Save operation on it.

StreamReader SR;
string S = "abc", filename = "", physicalPath ="";

string appPath = HttpContext.Current.Request.ApplicationPath;
physicalPath = HttpContext.Current.Request.MapPath(appPath);
filename = physicalPath + "\\Files\\temp.txt ";
File.SetAttributes(filename, FileAttributes.ReadOnly);
SR = File.OpenText(filename);



上面的代码确实将Readonly模式设置为该文件,但是在用户单击Button时该文件对用户不可见.

请让我知道解决方法.

谢谢n问候,



The above code does sets the Readonly mode to the file but the file is not visible to the user on Button click.

Kindly let me know the solution.

Thanks n Regards,

推荐答案

好吧,不.该文件对用户不可见-您所要做的就是打开一个流以读取文件.流在服务器内存中,文件在服务器硬盘上.用户在另一个大陆上.

如果希望用户能够在ASPX页面中看到该文件,则必须向其明确显示该文件.不幸的是,这确实意味着他将可以控制它:全选,复制将为他提供他可以保存的数据的副本,即使您禁用选择并通过javascript复制也不意味着他可以.没关系:大多数浏览器都允许查看源代码",该源代码将以HTML形式显示整个页面内容,而无需在其上运行任何JS代码.
Well, no. The file is not visible to the user - all you have done is open a stream to read the file with. The stream is in the server memory, the file is on the server harddisk. The user is on another continent.

If you want the user to be a able to see the file in your ASPX page, then you have to explicitly show it to him. Unfortunately, that does mean he will then be in control of it: Select All, Copy will give him a copy of teh data he can save, and even if you disable selection and copy via javascript that doesn''t mean he can''t get at it: most browsers allow "view source" which would show the whole page content in HTML without running any JS code on it.


这篇关于使用ASP.Net打开以只读模式对用户可见的.txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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