Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Media libraries folder storage location w/ Virtual Directory View modes: 
User avatar
Member
Member
ks-adaptdev - 2/6/2014 4:08:49 PM
   
Media libraries folder storage location w/ Virtual Directory
I'm seeing some bazar behavior, hoping someone can explain this to me.

In the SiteManager I set my media library location to "~/sitefiles" and checked the use site-specific folder box.

"~/sitefiles" happens to be a virtual directory. It maps to lets say "d:\web\files". I can confirm this by doing a Server.MapPath("~/sitefiles") and it outputs the correct physical path.

So when I upload a file to the media library, it succeeds, and Kentico tells me its direct path is something like /sitefiles/{sitename}/images/{filename}.jpg, as I would expect. Except, Kentico didn't actually save the file at MapPath("~/sitefiles")!, it saved it in my physical website folder root, eg. d:\websiterootpath\sitefiles\images...!

As a result, the logical path to the file /sitefiles/{sitename}/images/{filename}.jpg returns a 404 because the web server is physically looking in the virtual directory location (d:\web\files\{sitename}\images\{filename}.jpg).

This almost seems like Kentico isn't using Server.MapPath to resolve the physical path of the virtual file location I've provided. Could this be true?

Note: I have verified in a sample aspx page that saving a file to MapPath("~/sitefiles") does properly save it to the physical file location my virtual directory maps to. It's not an issue on my server/virtual directory configuration.

Help!

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 2/6/2014 4:21:52 PM
   
RE:Media libraries folder storage location w/ Virtual Directory
I'd use the Kentico IO namespace to do your path functions.

Regarding your setup.

When you check the "use site specific folder" box, that means whatever you entered in your media library location will have a sub folder with the site name. I don't do this with a single site install seems like overkill and makes for a long, useless URL.

I think what might fix your problem is simply removing the tilde (~) from your media library location.

User avatar
Member
Member
ks-adaptdev - 2/6/2014 4:57:07 PM
   
RE:Media libraries folder storage location w/ Virtual Directory
Removing the tilde doesn't help (good suggestion, though!) and it doesn't make a difference whether I "use site specific folder" or not.

I just decompiled the sources to CMS.IO and basically confirmed my suspicion:

return SettingsKeyProvider.WebApplicationPhysicalPath + path.Substring(1).Replace('/', '\\');

Kentico's internal GetPhysicalPath method does the above - it takes the known physical application path and concatenates the virtual path, stripping out the "~".

So in other words, you can't trust "~/path" paths to actually be mapped to the physical path on the server. It's really a map to the physical path of the website root plus whatever is after the "/". That's unexpected and a bad design decision, IMHO. I can't think of any useful reason for it behaving this way. It means you can't put media libraries in a Virtual Directory. :\

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 2/7/2014 6:19:12 AM
   
RE:Media libraries folder storage location w/ Virtual Directory
Have you checked both the global and site specific settings for this? Your site might have different settings in place which is why you are seeing the file stored in a different place. I've been working with Kentico since early v4.x and have never had a problem with media libraries and/or their URLs.

User avatar
Member
Member
ks-adaptdev - 2/7/2014 10:05:55 AM
   
RE:Media libraries folder storage location w/ Virtual Directory
Thanks FroggEye, another good tip. I had changed this particular setting at the global level. My site inherits it, and shows the same value, so I don't think that's an issue.

Have you ever configured the media library to point to a path that happens to be virtual? As someone who's new to Kentico, it's misleading how tilde "~/paths" work, at least as it pertains to the media library configuration. The tooltip says:

"Physical path to the folder where root folders of all media libraries should be stored. For example "~/Libraries", "c:/Libraries" or "\\servername\Libraries". If empty "~/[site name]/media" will be used."

Lets say my site lives at c:\wwwroot\site

So if I put in "~/Libraries" and then upload a file to the library, you'd expect it to end up physically saved on disk at c:\wwwroot\site\Libraries, with the url /Libraries/{file}. This is true.

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}.

Does that make sense? Is there anything I'm missing?

Note: I'm aware I could just configure the media library w/ a physical path of c:\files instead of the virtual path, but I'm hosting the site on a cloud provider and technically I don't have control over the physical path of my system (it could change, be different across different instances, etc).

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 2/28/2014 3:02:44 AM
   
RE:Media libraries folder storage location w/ Virtual Directory
Hi,

You are right with your findings. Unfortunately this is not supported in current version. I have already notified our development and product management teams about this and I hope they will be able to change the way how it works soon. I am sorry for the inconvenience.

Best regards,
Juraj Ondrus

User avatar
Member
Member
ks-adaptdev - 2/28/2014 8:57:04 AM
   
RE:Media libraries folder storage location w/ Virtual Directory
Thanks for the confirmation and for notifying the team, Juraj!