如何使下载的文件C#Asp.net过期 [英] how can expired the downloaded files c# asp.net

查看:124
本文介绍了如何使下载的文件C#Asp.net过期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建ftp项目或文件共享项目以将我的文件上传到ftp服务器上,然后向用户发送电子邮件以在链接中下载此文件,并且我需要在特定时间后通过代码阻止用户使用此链接. ="h2_lin">解决方案

ASP.NET以及所有其他服务器端Web技术的整个思想是通过在服务器上处理HTTP请求来动态生成HTTP响应中的内容.并在发送响应之前进行所需的计算.本质上,这就是ASP.NET的全部功能.

此响应可以是任何内容,不仅可以是HTML.它可以是动态生成的任何文件.例如,如果您提供PNG文件,则其内容类型"应为"image/png",这是HTTP标头之一.可以直接在ASP.NET页面中引用ASP.NET页,而不是直接在src属性中的<img>元素中引用该文件,该页面后面的代码读取该文件并将其写入带有适当头的HTTP响应中.请参阅: https://msdn.microsoft.com /en-us/library/System.Web.HttpResponse%28v=vs.110%29.aspx [ https://en.wikipedia.org/wiki/Internet_media_type [ https://www.iana.org/assignments/media-types/media-types.xhtml [ ^ ],
https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Response_message [ https://en.wikipedia.org/wiki/List_of_HTTP_status_codes [ 解决方案

The whole idea behind ASP.NET, as well as all other server-side Web technology, is that you generate content in HTTP response dynamically, by processing HTTP request on the server side and doing required computations before sending the response. Essentially, this is all ASP.NET does.

This response can be anything, not only HTML. It can be any file generated dynamically. For example, if you deliver PNG file, its "Content-type" should be "image/png", which is one of HTTP headers. Instead of referencing the file directly in a <img> element in src attribute, you can reference ASP.NET page which code behind reads the file and writes it in HTTP response with proper headers. Please see:
https://msdn.microsoft.com/en-us/library/System.Web.HttpResponse%28v=vs.110%29.aspx[^].

And then, in the middle, you check up the user''s data, including authentication. You can store all the time stamps per each downloaded resources, compare with current time, and then decide if you want to deliver that file, or, instead appropriate response message explaining the problem, or even on of the error status codes 4??, (such as 417, see the last link below :-)).

See also:
https://en.wikipedia.org/wiki/Internet_media_type[^],
https://www.iana.org/assignments/media-types/media-types.xhtml[^],
https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Response_message[^],
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes[^].

—SA


There is no built-in way to do it. However, one way is to generate a timestamp and then encrypt it and put it into the querystring of the link. Then in your page that the link goes to, get the querystring value, decrypt it, and compare it to the system clock.


thanks for your support but i have created two folders and create a function to move the files that uploaded by user to the second folder after certain period


这篇关于如何使下载的文件C#Asp.net过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发语言最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆