Copied to clipboard

Flag this post as spam?

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


  • Dan Meineck 1 post 71 karma points
    Nov 05, 2015 @ 16:13
    Dan Meineck
    0

    MediaService.Delete Clears ASP.NET Session

    Hi All,

    I'm using umbraco to perform some actions against the API in my MVC controller action following a form submit. All works fine.

    The code uploads a new image, adds it using the MediaService, and then removed the previous image using the MediaService.

    I've just got to the point where I've implemented the removal logic, where I call :

    public bool DeleteMediaItem(Uri mediaItemUri) { if (mediaItemUri == null) { return false; }

    var mediaService = UmbracoContext.Current.Application.Services.MediaService;
    
    var mediaItem = mediaService.GetMediaByPath(mediaItemUri.ToString());
    if (mediaItem == null)
    {
        return false;
    }
    
    mediaService.Delete(mediaItem);
    return true;
    

    }

    If I comment out the line mediaService.Delete(mediaItem); then all works fine. However when left in, subsequent HTTP requests against my site have an empty ASP.NET Session.

    Is this a known issue?

    Thanks,

    Dan

  • Bijesh Tank 192 posts 420 karma points
    Jan 12, 2016 @ 09:31
    Bijesh Tank
    0

    I'm doing something very similar I get this issue too, using version 7.3.3. Were you able to get a work around on this issue?

    For the time being I had to use .MoveToRecycleBin, i.e. in your case

    mediaService.MoveToRecycleBin(mediaItem);
    

    Not exactly ideal as it means it will require someone to empty out the recycle bin every now and again, or create a timed event that regularly empties it.

    B.

Please Sign in or register to post replies

Write your reply to:

Draft