Serve up file from outside wwwroot

I am migrating an ASP.NET4.5 website to ASP.NET 5. One function we had returned images off the hard disk from an absolute location. The files arent stored within the web directory. Previously this worked fine, with the following code:

public ActionResult GetVideoImage(string serialNumber, int videoEntryId)
{
    try
    {
        var serial = Device.FriendlySerialNumberToNumericalSerialNumber(serialNumber);

        var entry = this.service.GetVideoEntry(serial, videoEntryId);

        if (entry != null && System.IO.File.Exists(entry.FirstVideoFrameLocation.LocalPath))
        {
            return this.File(entry.FirstVideoFrameLocation.LocalPath, "image/jpeg"); // adjust content type appropriately
        }
    }

    return this.Redirect("/content/noimage.png");
}

Unfortunately this doesnt work anymore and throws an exception. From what I can tell its because this.File now takes a virtualPath rather than an absolute one so balks at the idea of serving a file from outside of its web directory.

  • How can I get around this?
  • Also is ActionResult still the best return type for this?

Answers


I found the answer on a MS thread here that links to a ASP github commit.

Long story short there are new classes available in the Microsoft.AspNet.Mvc namespace that allow the thing I'm looking for. I specifically chose PhysicalFileResult which works as expected


Need Your Help

How to get the Freeman chain code in OpenCV?

c++ opencv

I am trying to obtain the Freeman chain code using the findCountours function but I'm unable to understand its parameters, and an explanation is not given for each parameter in the OpenCV documenta...

Get selected text when receive shared data in windows phone

windows-phone-8 share uwp

have question about windows phone (UWP) app. Now we have opportunity to receive data if you subscribing for share data. So, user can click share page in IE on windows phone and send this page to fa...