2

Closed

Invalid url generated for static files outside of the root of the project

description

If I'm specifying a subfolder in StaticFilesFolders settings property, for example:
readonly string[] StaticFilesFolders = new string[] { "MyStaticContent\Images" };
and in my view I'm writing a code
@Links.Images.Logo_png I have an output as /Images.Logo.png
The library just asumes that project item Images is located at the root.

To fix it I've changed a content of the next method:
void ProcessStaticFiles(Project project, string folder) {
ProjectItem folderProjectItem = GetProjectItem(project, folder);
if (folderProjectItem != null)
{
    var rootPath = "~";
    if (folder.Contains("\\"))
    {
        rootPath += "/" + folder.Replace("\\", "/");
        rootPath = rootPath.Substring(0, rootPath.LastIndexOf("/"));
    }
    ProcessStaticFilesRecursive(folderProjectItem, rootPath);
}
}

Maybe we should create internal class and generate it as Links.MyStaticContent.Images.Logo_png, but in my case it removes unnecessary nesting. But be careful, because there will be a conflict if you specify settings as
readonly string[] StaticFilesFolders = new string[] {
"MyStaticContent\\Images",
"MyAnotherStaticContent\\Images"
};
Closed Feb 13, 2013 at 11:03 PM by davidebbo
Closing as I didn't hear back.

comments

davidebbo wrote Aug 7, 2012 at 6:34 PM

Yes, the conflict situation could indeed happen if we're not careful. Maybe another approach is to let the user specify an optional alias for a given path to disambiguate.

In any case, what you have won't break any scenarios that worked before (I think!), so maybe we can start with that and go from there.

Would you be able to send a pull request with the change? Thanks!