How to make image URLs relative with custom provider?

Posted by cmsdev on 15-Aug-2019 18:08

Hi:

I am new to SiteFinity and need to get something done quickly. There is a lot of information out there and I have the basic concepts but missing the concrete steps to get my task done. I am working with SiteFinity 10.2

Currently, Sitefinity outputs IMG tags with src based from the root. For example, <img src="/images/default-source/default-album/..." />. I would like to alter the behavior so that it does not reference the images from the root. I'd like it to be <img src ="images/default-source/default-album/..." />.

Based on my research, I believe this can be done by creating a provider similar to this example:

https://www.progress.com/documentation/sitefinity-cms/for-developers-change-url-format-for-modules-with-multiple-content-types

A few questions:

1. How do I reference the Telerik.* dlls in my project. I did not find nugets for them. Do I need to install/use the Sitefinity Project Manager to create my projects?

2. Once I create and compile my dll, how do I deploy it to my server? The server is hosted elsewhere and I do not have access to the machine to "publish" a build. However, I notice in the administrator interface, there is a file manager. Can I use the file manager to upload to the /bin folder? 

Any information would really be helpful, thank you.

All Replies

Posted by craig.holdheide on 16-Aug-2019 12:48

Hello cmsdev,

Before I answer the two questions at the bottom of your post, I am curious why you prefer to have a relative source path to your images?  Just trying to understand what the value of doing this would be.  Sitefinity uses something called a virtual path provider, which is a fancy way of saying if I go to the URL that starts with /images/ I can pull images from an alternate source.  In the case of Sitefinity, it will store images in the database by default.

To answer your questions...

1. How do I reference the Telerik.* dlls in my project. I did not find nugets for them. Do I need to install/use the Sitefinity Project Manager to create my projects?

A:  I would take a look at http://nuget.sitefinity.com.  You can add this nuget feed to visual studio and you should be able to find the Telerik assemblies you need.  I normally reference the Telerik.Sitefinity.Core (now called Progress.Sitefinity.Core) package to access the base functionality of Sitefinity.

2. Once I create and compile my dll, how do I deploy it to my server? The server is hosted elsewhere and I do not have access to the machine to "publish" a build. However, I notice in the administrator interface, there is a file manager. Can I use the file manager to upload to the /bin folder?

A:  You can do this, but I typically would not recommend it.  BUT, if you are going to do this I would do the following...

Deploying Assemblies using Sitefinity File Manager

  1. Download and backup any assemblies you intend to overwrite
  2. Upload the new Assemblies
  3. Edit the web.config (add a space to the end of the file and this will cause the website to restart and load the updated DLLs into memory)

Hope this helps.

Craig

Posted by cmsdev on 16-Aug-2019 16:34

Hi Craig:

Thanks so much for taking the time out to respond to my question.

The reason I need to remove the root "/" is because we have the sitefinity site behind a "virtual directory". We have a proxy that redirects all traffic from our main site (www.myco.com) to a path below the main domain (www.myco.com/mycmssite). When we have it configured in this way, none of the images display because the browser is requesting them from www.myco.com/images/default-source/default-album instead of www.myco.com/mycmssite/images/default-source/default-album.

The leading "/" brings the URL back to the root of the domain. If I could diagram:

                         |P|

Browser -------> |R|-------------www.myco.com------>web server

                         |O|

                         |X|-------------www.myco.com/mycmssite/*   ----> sitefinity server

                         |Y|

If you know of a better solution (i.e. specifying a virtual path in SiteFinity's config somewhere), that would really be helpful.

Thanks again!

Posted by craig.holdheide on 16-Aug-2019 17:39

In IIS you can convert a virtual directory to an Application.  Just right-click the virtual directory and select "Convert to Application".  I would then select a different application pool for this subsite, and click ok.  Restart the app pool and see if that helps.

Let me know if that resolves your issue.

Thanks,

Craig

Posted by cmsdev on 16-Aug-2019 17:41

It is not a real virtual directory. It is a redirect from our proxy.

Posted by craig.holdheide on 16-Aug-2019 19:05

Got ya.  Try the following below, but no guarantee these will work.  This is a pretty interesting configuration.

If you DO NOT have the multisite module, go to Administration > Settings > Advanced.  On the left-hand menu select System > Site URL Settings.  Check Enable non-default Site URL Settings and set The Host to "www.myco.com/mycmssite", save changes, and restart the site

If you running the multisite module, on the Sitefinity backend, click the site selector then select Manage Sites.  Then click your site to view the site details.  On the Edit a site screen set the domain to "www.myco.com/mycmssite".  Save the changes.

Let me know if this helps.  I will keep thinking about this one and let you know if I come up with more ideas.  Thanks.

Craig

Posted by cmsdev on 16-Aug-2019 19:48

Hi:

Dumb question, but short of renaming web.config file, is there a way to "restart" the server without access to IIS server?

Also, should I go the route of a custom open data provider, would you know which class to derive from for Images? I'm not sure if it is Library or Content. I search object browser for "getUrlFormat" method from the linked example. I didn't find an "Images" class like the "Blog" class in the example.

Thanks again!

Posted by alan.wallace@oit.edu on 16-Aug-2019 20:19

It would be nice if there was just a restart button somewhere but something else that will have the same effect in the Sitefinity backend is to go to Administration->Settings, then select "User Authentication" in the left menu and click "Save changes"

Posted by craig.holdheide on 16-Aug-2019 20:21

To restart the site without access to the server, you can make a small change to the web.config file (not the name of the file).  For example, just add an extra space at the end of the file and save it.  That will cause the website to restart.

Also, I would not go the route of the custom open data provider.  Even if you get it working, there are other data providers you would have to do the same for and that would turn into a lot of technical debt.

Since you don't have direct access to the servers and you cannot deploy code easily, there are only so many things you can do.  I would try talking to the owners of the servers and see what can be done to help you resolve your situation.  

Again, if I can think of any other ideas I will let you know.  Have a great day.

Posted by craig.holdheide on 19-Aug-2019 17:38

Check out this link on the Sitefinity docs site...

www.progress.com/.../run-a-sitefinity-instance-as-parent-or-child-of-an-asp-net-application

It might also help you with your situation.

Craig

Posted by cmsdev on 19-Aug-2019 22:06

Hi Craig:

Thank you for your continued thoughts. I don't think that link will be helpful since these are proxy redirects.

However, my latest idea is perhaps to create my own widget and output the HTML myself. The only question I would have there is if it would be possible to have my widget access the image library as the built-in widgets. How much effort would be involved in going this route?

Posted by craig.holdheide on 22-Aug-2019 02:41

I hate to say it, but it depends.  I normally try to use the out of the box widgets as much as possible before I resort to a new widget.  

But, also knowing the situation you are dealing with, you may have no other choice but to create a custom widget.

Also, something else to consider... is it possible to move your site to a different domain or a subdomain.  This is a lot less technical and could be a simpler solution to your problem.

Without seeing any more specific details about this problem, it may be hard for me to recommend a viable solution.  

Again, good luck, and if I come up with additional ideas or come across anything that might be useful, I will be glad to pass it along.

Thanks,

Craig

Posted by markmazelin on 22-Aug-2019 16:09

Another thought -- can you use IIS rewrite rules on the web server to rewrite all requests directed at /images/* to point to /mycmssite/images/*?

This thread is closed