c# - Retrieve external html file and securely display in browser -
i working on online publication subscription site. developed in asp.net mvc 1.
basically, user purchases magazine or newspaper , path publication becomes available them. however, catch 22 is, not allowed see filepath publication unsecured.
i've built function can retrieve publication , download without showing filepath user problem because publication html file needs other files , folders in same directory view magazine or newspaper.
i know might download entire directory folder, unreasonable can 200mb. thought maybe retrieving filepath , redirecting page load publication in iframe think security risk bit of knowledge of browsers can view source , filepath there.
if has suggestion of secure way retrieve html file , display in browser, appreciated. thanks.
easy! store secret urls in database table, , reference them id instead.
set new controller action follows:
public contentresult shownewspaper(long id) { var mysecreturl = db.secreturls.where(k=>k.id == id).firstordefault(); // grab url entry database string htmlcode = ""; if(mysecreturl != null) { webclient client = new webclient(); htmlcode = client.downloadstring(mysecreturl.url); }else{ htmlcode = "page not found!"; } return content(htmlcode,"text/html"); }
so if call:
mysite.com/home/shownewspaper/5
this load html @ url stored in database record 5
you go step further , check see whether or not controller action called site (as opposed directly) checking referrer.
hope helps...
edit: store "authorised user id" in database record too, , check accessible if id matches logged in user id, prevent unauthorised access controller action , therefore magazine... if not, redirect them login screen
return redirect("/myloginurl");
Comments
Post a Comment