Virtual directories for media folder in K12

Aaron Macdonald asked on August 19, 2021 04:15

Hello

We have a K12 MVC site hosted in IIS and would like the media folder to sit outside of the physical website folder, on the same drive.

We'd like to achieve this in the simplest manner by creating an IIS virtual directory.

However after testing this we find that uploaded files are not saved to the virtual directory physical location.

There is a post which references this scenario from 2014 and indicates that it is a bug, whereby the location is not correctly mapped.

https://devnet.kentico.com/forums/f65/t43887/media-libraries-folder-storage-location-w-virt

Can someone please confirm that this is an existing bug, and whether there is any timeline to resolve it?

Correct Answer

Juraj Ondrus answered on August 19, 2021 08:41

I am afraid but there were not made any changes in this regards. Kentico in this settings works with web root relative paths (/foldername) or absolute physisal paths (c:\forldername) or UNC path (\server\folder), as described in the documentation. It does not take into account IIS Virtual paths. You can submit this as a feature request to our product management team using this link.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Juraj Ondrus answered on August 19, 2021 07:30

What is the media files folder setting in Settings application under the Content -> Media -> Media libraries folder? I just tested it and it is working fine even without IIS virtual directory. What is the reason to use this as virtual directory in the IIS?
I set the media files folder to be like c:\TestFolder. Then I created a new media library and the ~/< sitecodename >/< libraryname > folder was created inside the TestFolder. Then, the uploaded files were stored there just fine. I also create a virtual directory in the IIS for that TestFolder - no change, everything works fine.

0 votesVote for this answer Mark as a Correct answer

Aaron Macdonald answered on August 19, 2021 08:33

Ok so Content -> Media -> Media libraries folder is the default (i.e. not set). According to the tool tip that default is ~/{site name}/media.

We don't want to hardcode physical paths like C:\TestFolder.

We just want to create an IIS virtual directory for /media which points to a physical location outside the website location, and would expect Kentico to use Server.MapPath() to determine the physical location when it is writing files to that folder.

Regarding this scenario we refer back to the post made by ks-adaptdev in 2014 in the provided link:

...

But, configure the path "/Libraries" in IIS to be a virtual directory, which maps to the physical path of c:\files.

Again, we'll configure Kentico to use "~/Libraries". Upload a file, and you'd expect it to end up physically saved to disk at c:\files with the url /Libraries/{file}. This would be standard .net behavior assuming the code written to save the file calls Server.MapPath("~/Libraries") to determine the physical location. But this isn't what is happening.

Kentico ends up ignoring the fact that /Libraries is virtual, and saves the files physically on disk at c:\wwwroot\site\Libraries. This is not what one would expect. This means your files aren't saved where you wanted them and the Urls to them 404 because IIS is looking for the physical file at c:\files{file}.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.