Copied to clipboard

Flag this post as spam?

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


This forum is in read only mode, you can no longer reply
  • Mário Nunes 7 posts 87 karma points
    Feb 15, 2018 @ 16:52
    Mário Nunes
    0

    Image protection for non authenticated users

    Hello,

    Is there a way to show images for authenticated users only?

    I'm using owin authentication.

    I know of the ImageProcessingModule.ValidatingRequest event, but it runs only the first time an image is requested. If the image is in cache already, it will be displayed.

    Is there a way to catch and stop the cache request?

    Has anyone solved a similar problem?

    Thanks!

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    Feb 15, 2018 @ 19:06
    Alex Skrypnyk
    1

    Hi Mário

    You can do nothing with web browsers cache, the only thing you can do - set an expiration time for the images something like 0. Did you mean browser cache?

    Thanks,

    Alex

  • Mário Nunes 7 posts 87 karma points
    Feb 16, 2018 @ 13:45
    Mário Nunes
    0

    Hi Alex

    No, I mean the imageprocessor cache.

    Thanks.

  • James Jackson-South 489 posts 1747 karma points c-trib
    Feb 18, 2018 @ 07:48
    James Jackson-South
    100

    I know of the ImageProcessingModule.ValidatingRequest event, but it runs only the first time an image is requested. If the image is in cache already, it will be displayed.

    I don't know where you got that idea. OnValidatingRequest is called for every request.

    https://github.com/JimBobSquarePants/ImageProcessor/blob/809f2b0763441f307c6a00ee10cea5f6cd4b9d4b/src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs#L496

    The cache is not checked until after.

    https://github.com/JimBobSquarePants/ImageProcessor/blob/809f2b0763441f307c6a00ee10cea5f6cd4b9d4b/src/ImageProcessor.Web/HttpModules/ImageProcessingModule.cs#L576

    If in doubt always check the source.

    As Alex said, you're probably seeing the result of the browser cache. There's a config setting browserMaxDays where you can reduce that to 0 days.

  • Mário Nunes 7 posts 87 karma points
    Feb 18, 2018 @ 12:05
    Mário Nunes
    0

    Thanks James,

    You are right, it is called on every request.

    I figured it out, what was happening was that even after setting e.Cancel to true, it would still return the image. But that image was the original from Umbraco without being processed. That's what caused the confusion.

    My solution was to abort the request.

    e.Context.Request.Abort();
    e.Cancel = true;
    return;
    

    Thanks guys, you rock! :D

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies