8

We are using DD4T on SDL Tridion 2011 SP1 HR1. When presenting images from within a RTF we note that the root path is added twice to the image path/filename.

We have configured the web app under a virtual path /vpath/ as read from the webserver variables HttpContext.Current.Request.ApplicationPath.

Images are being presented to the deployed environment as /vpath/vpath/images/image-name.jpg - any ideas if we're missing a configuration to indicate the path prefix is not required?

We originally setup the publication with the /vpath part in the URL in the Publications Settings Path and later the requirement (IT team) was to setup the application to run under a virtual directory.

We'd initially thought we could reuse a web.config setting we have to indicate that the application runs under a virtual directory (for other functional requirements)

<add key="VirtualDir" value="vpath" />

and just update the method to:

    public static string AdjustUrlToContext(string url)
    {
        if (!string.IsNullOrEmpty(System.Configuration.ConfigurationManager.AppSettings["VirtualDir"]) 
            return url;

        return HttpContext.Current.Request.ApplicationPath + url;
    }

But we also need to consider if we create another publication and the publication setting does not include the virtual path.

Update:

Indeed, the proper solution would be to not have the virtual path in the publication path but given we are stuck where we are right now and need a fix before re-visiting,

we could check if the URL passed in already starts with the VirtualDir and then remove it... I don't like the idea of just removing full stop... I know we can 'manage' this going forward by not having the prefix in the publication settings but it assumes too much.

So let's imagine we do have a /anothersite/anothersite/index.aspx ... the above code is saying this is simply not allowed as a consequence of a legacy issue. Bad times.

5
  • OK. So I can see in the General class in DD4T.Mvc.Utils that we add context (AdjustUrlToContext) to the URL. It seems that there's no specific config to allow for an application running under a specific virtual directory. Commented Sep 25, 2013 at 8:55
  • 1
    Have you checked the Images Path setting on the Publication properties in the CME? Commented Sep 25, 2013 at 9:06
  • Cheers Nick... was just updating the question after seeing this. One challenge is that the requirements changed and with the site live it was deemed to high-risk to update this value... Commented Sep 25, 2013 at 9:11
  • @dylan while I agree that simply changing it on a live environment is indeed too high of a risk (besides the fact that you need to republish the entire website after that, since you changed a value used in all Pages). It could however still be worth investigating that a change on an acceptance environment, as leaving it incorrectly set might cause you more problems in the future. Commented Sep 25, 2013 at 11:49
  • @Bart - Absolutely correct. We have requested time from the client to retrospectively investigate this once we have the current 'live' issue of rendering images correctly resolved. Much better to bite-the-bullet now and resolve than when the site is 10x bigger (or someone else copies the same, incorrect, format on another publication/site) Commented Sep 25, 2013 at 14:15

1 Answer 1

5

For information...

As this is specific to a 'legacy' post-implementation issue that we can't simply reverse without a full site re-test etc. we have opted for the following solution.

If we have a VirtualDir setting in the web.config we also include a simple (albeit verbose) VirtualDirIncludedInPubSettings value which we can set to true if we want to execute a snippet to remove the prefix if it's (retrospectively incorrectly) added.

This solves the problem now, allows for future sites to be configured 'correctly' and also allows us to correct this site and just tweak the config when time permits.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.