.net - Temporary file download link with ASP.NET -


i'd know how can generate temporary download address file limited time. know that's not best practice , using httphandlers way go according http://www.devx.com/codemag/article/34535/1954
i'm curious know how can use urlrewriting generate file name using guid or other cryptic naming technique , make available limited time.
i'd appreciate if points me article it.

well first need form of identifier. suggest guid , that's done, guid.newguid().tostring("n") gives such identifier.

you talk of uri rewriting, that's bit of polish. rewriting turn /myfiles/a948ec43e5b743548fd9a77c462b953e /myfiles/download.aspx?id=a948ec43e5b743548fd9a77c462b953e or (after checking table) myfiles/download.aspx?id=3 or myfiles/download.aspx?filename=mynewdownload.pdf. same other uri rewriting task, lets ignore , assume we've request coming /myfiles/download.aspx?id=a948ec43e5b743548fd9a77c462b953e whether due rewriting or not.

okay. you've got identifier, need match 3 things: stream, content type , expiry date.

you store of in file system, of in database or details in database including path stream stored file in filesystem.

lets store in file system names like:

a948ec43e5b743548fd9a77c462b953e.application_pdf , a5d360178ec14e97abd556ed4b7709cf.text_plain;charset=utf-8

note aren't using normal windows file extensions, deal case uploading machine had different bindings server.

in case of a948ec43e5b743548fd9a77c462b953e being item required first @ creation date , if it's long ago (the file has expired), send 410 gone header error message explaining file has expired (we can delete file @ point clean usage - or perhaps truncate remains record file used exist, 0bytes of storage).

otherwise set response.contenttype "application/pdf" , response.transmitfile send file.

if we'd stored stream different way file, we'd want send in small chunks (4096 nicely matches other buffers in other parts of system) , in case of being large call response.flush() periodically prevent memory issues.

that's basic system done. niceties include storing original file name , sending in content-disposition header, , obeying range requests user can resume failed download rather have start beginning.

all of pretty orthogonal authentication used ensure correct person has file - use in tandem login system of whatever sort, or leave public time-limited.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -