Search code examples
iisiis-7umbracoumbraco7

How to implement Umbraco 7.x website as a virtual directory in IIS 7.5?


I have a website developed using Umbraco 7.3 and it's working perfectly without any problems if I installed as a website under IIS 7.5, the problems started when I want to use as a virtual directory.

Problems:

  1. Images not loadining in the website (404 not found)
  2. 404 errors for .CSS files
  3. 404 errors for .JS files

I was able to solve the 2nd and 3rd problems using the following:

  • adding <ResolveUrlsFromTextString>true</ResolveUrlsFromTextString> under <content> in the umbracoSettings.config file in Config folder.
  • I've Updated all the JS & CSS path from "/js/*" to "~/js/*" and "/css/*" to "~/css/*".

but the 1st problem of the images still I couldn't solve, any help will be appreciated.


Solution

  • After a lot of searches, finally I was able to make it work without a single problem, following are the steps I did to implement Umbraco 7.x website as a virtual directory:

    1. Open the umbracoSettings.config file in the Config folder and insert this code <ResolveUrlsFromTextString>true</ResolveUrlsFromTextString> between the <content>tag.
    2. Update all of the JS & CSS paths in your main Template you are using as a master Templat from "/js/*" to "~/js/*" & "/css/*" to "~/css/*" also Add runat="server" attribute to the <head> tag or to each .CSS link in the header like this example: <link href="~/Css/main.css" rel="stylesheet" type="text/css" runat="server"/> like the image:

    enter image description here

    1. Finally, this is the most important point, fixing the images links or the Media folder, to do this open SQL server and run the following query in the Umbraco DBUPDATE cmsPropertyData set dataNvarchar = replace(dataNvarchar, '/media/','/replaceWithvirDirNameHer/media/') where dataNvarchar like '/media/%' and don't forget to change replaceWithvirDirNameHer with the actual virtual directory name.
    2. Restart the IIS and republish entire site like the image:

      enter image description here

    Important Note:

    Some links may not reflect the changes and this is due to its path is fixed, so we need also to do them and not to forget, like the image:

    enter image description here

    I hope this will help.