Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Josefine 27 posts 139 karma points
    Apr 16, 2024 @ 17:30
    Josefine
    0

    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

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Apr 16, 2024 @ 17:54
    Huw Reddick
    0

    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.

  • Josefine 27 posts 139 karma points
    Apr 17, 2024 @ 06:55
    Josefine
    0

    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?

        [Route("Media/{id}/{file}")]
        public IActionResult Index(string id,string file)
        {
        }
    
  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Apr 17, 2024 @ 07:35
    Huw Reddick
    0

    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

  • Josefine 27 posts 139 karma points
    Apr 19, 2024 @ 19:09
    Josefine
    0

    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?

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Apr 20, 2024 @ 17:29
    Huw Reddick
    0

    No unfortunately, that is why the first bit of code checks to ensure it is a media request and bails out if not.

  • Josefine 27 posts 139 karma points
    Apr 21, 2024 @ 07:25
    Josefine
    0

    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 🙂

Please Sign in or register to post replies

Write your reply to:

Draft