How to protect a folder or file in media in Umbraco 13?
In Umbraco on a folder or file, I want to select the member type or member group that should have access to visit these files. Only when you are logged in as that member type or member group do you have access to visit the file
You can add a group/member picker to the media type and/or folder, but you will then need to write some middleware that does the actual checking. There should be some example code here on the forum explaining how to do that.
I have added group/member picker to the media type and/or folder and created a MediaProtectController.cs. But when I visit the file url I don't hit the controller. Do you have any tips?
[Route("Media/{id}/{file}")]
public IActionResult Index(string id,string file)
{
}
Ok my media controller in Umbraco version 9 only hit the media request so it would be nice to optimize this request some. Thanks for all your help 🙂
How to protect a folder or file in media
Hi
How to protect a folder or file in media in Umbraco 13?
In Umbraco on a folder or file, I want to select the member type or member group that should have access to visit these files. Only when you are logged in as that member type or member group do you have access to visit the file
Josefine
You can add a group/member picker to the media type and/or folder, but you will then need to write some middleware that does the actual checking. There should be some example code here on the forum explaining how to do that.
Thanks for your reply!
I have added group/member picker to the media type and/or folder and created a MediaProtectController.cs. But when I visit the file url I don't hit the controller. Do you have any tips?
Hi,
Unfortunately you can't do this with a controller, you need to write a middleware class and register it during startup.
This post https://our.umbraco.com/forum/using-umbraco-and-getting-started/108979-intercept-all-media-requests#comment-338270
might help get you started
Yes, now it works! Thank you very much :-D
InvokeAsync receives all requests, like /umbraco, /css, etc. Is it possible to filter the requests before entering InvokeAsync?
No unfortunately, that is why the first bit of code checks to ensure it is a media request and bails out if not.
Ok my media controller in Umbraco version 9 only hit the media request so it would be nice to optimize this request some. Thanks for all your help 🙂
is working on a reply...