0

I need to block users for downloading some PDF files if a session is not null and if the file is marked as private (checked trough DB table)

I have tryed global.ascx solution but I can't access in none of this events AcquireRequestState, PreRequestHandlerExecute the session state..

Any ideas?? Thanks!

ricardo_escovar
  • 447
  • 4
  • 5
  • What do u mean by session is not null ? – Nikhil Vartak Apr 14 '16 at 19:29
  • So you're saying that during the `Application_AcquireRequestState` event, `HttpContext.Current.Session` is null? [That event gets called a lot, so the session will be null _sometimes_](http://stackoverflow.com/questions/33088530/session-is-null-in-acquirerequeststate-when-loading-virtual-directory-name-in-br) – stuartd Apr 14 '16 at 19:31
  • 1
    Have you tried writing a custom handler to manage PDF delivery? http://stackoverflow.com/questions/19123961/filehandler-in-asp-net/19124733#19124733 – MikeSmithDev Apr 14 '16 at 20:39
  • Hi @nikhilvartak the session is started in an application... So if the session is not null and have a value, then you will be able to download the file. If you receive the link to download the pdf you won't be able to download the file unitl you enter into a web page that assign a value to the session... – ricardo_escovar Apr 15 '16 at 09:42
  • Hi @MikeSmithDev the session is not null.. I get an error that Session State is not available all the time the event is called... – ricardo_escovar Apr 15 '16 at 09:44
  • @MikeSmithDev will check that custom Handler, thanks!.... Does this will work even when the link is called outside the web page? – ricardo_escovar Apr 15 '16 at 09:46
  • @MikeSmithDev I did try the code that you suggested, but i'm getting that context.Session is always null, so I can't get any session... Any Ideas? – ricardo_escovar Apr 15 '16 at 11:42
  • @ricardo_escovar yes it will work for any link to a PDF. – MikeSmithDev Apr 15 '16 at 11:43
  • 1
    @ricardo_escovar check http://stackoverflow.com/a/14181556/1810243 – MikeSmithDev Apr 15 '16 at 11:45
  • Thank you very much @MikeSmithDev Everything is working now!!.. – ricardo_escovar Apr 15 '16 at 13:30

0 Answers0