I've been tasked with updating an existing site which has protected media on it. When a user requests a protected item, the permissions are checked and then the file is served (if the user has access) like so:
var fileBytes = System.IO.File.ReadAllBytes(filepath);
return File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, downloadItem.FileName);
Otherwise the user is bounced to a login page.
But now we've moved the site to use blob storage for media this no longer works.
The solution that springs to mind is to use a http module to handle the permissions checking, and then let Umbraco serve the file when the logging is complete. However, I don't have context in the http module and I'm struggling to use the MediaProtect library HasAccess method.
Is it possible to use MediaProtect in this way, or is there a better solution?
Yeah I could have kept that question a bit shorter, the blob storage is a bit of a red herring.
I was struggling to use the MediaProtect library functions in a HTTP module. The reason is I was using the BeginRequest method, which is too early in the pipeline. Using the PostAuthenticateRequest method solved my problem.
Now method calls like MediaProtect.Library.Library.GetCurrentUserName() work correctly and I can try and deal with the other issues ;)
Checking media access in a http module
Hi all,
I've been tasked with updating an existing site which has protected media on it. When a user requests a protected item, the permissions are checked and then the file is served (if the user has access) like so:
Otherwise the user is bounced to a login page.
But now we've moved the site to use blob storage for media this no longer works.
The solution that springs to mind is to use a http module to handle the permissions checking, and then let Umbraco serve the file when the logging is complete. However, I don't have context in the http module and I'm struggling to use the MediaProtect library HasAccess method.
Is it possible to use MediaProtect in this way, or is there a better solution?
Cheers,
David
Hi David,
Not sure I understand but with V2 of Media protect BLOB is already supported see chapter 7 of the manual https://soetemansoftware.nl/media-protect/downloads
Is this what you are after?
Best,
Richard
Hi Richard,
Yeah I could have kept that question a bit shorter, the blob storage is a bit of a red herring.
I was struggling to use the MediaProtect library functions in a HTTP module. The reason is I was using the BeginRequest method, which is too early in the pipeline. Using the PostAuthenticateRequest method solved my problem.
Now method calls like MediaProtect.Library.Library.GetCurrentUserName() work correctly and I can try and deal with the other issues ;)
Thanks,
David
is working on a reply...