Technical support This forum is closed.
Version 1.x > Technical support > Different virtual paths View modes: 
User avatar
Member
Member
wtijsma - 5/3/2005 10:18:19 AM
   
Different virtual paths
Hi Petr,

I use a different IIS path for my (development server) notebook and production server, i.e. and '/kenticoCMS/...' and '/'. This causes trouble with the image paths and the links edited in the FCK Editor.

this code (in my custom FCKEditor usercontrol, inherited from KenticoUserControl) replaces all the /kenticoCMS/... links and href's with ~/ and backwards. Not sure if it's completely bugfree (other configurations might cause trouble with double slashes), but it works:

///<summary>Gets or sets field value.</summary>
[DefaultValue("")]
public override Object Value
{
get { return ProcessLinks(Text, false); }
set { Text = ProcessLinks((string) value, true); }
}

private string ProcessLinks(string content, bool set)
{
if (content == null) return "";

string filespath = ConfigurationSettings.AppSettings["CMSFilesFolder"];
string virtualPath = ConfigurationSettings.AppSettings["CMSWebApplicationVirtualPath"];

if (filespath==null)
throw new ConfigurationException("setting 'CMSFilesFolder' has an invalid or no value");

if (virtualPath==null)
throw new ConfigurationException("setting 'CMSWebApplicationVirtualPath' has an invalid or no value");

if (filespath.StartsWith(virtualPath))
{
string serverPath = "~/" + filespath.Substring(virtualPath.Length + 1);
string clientPath = filespath;

string findString;
string replaceString;

// check if the property is being set
if (!set)
{
findString = clientPath;
replaceString = serverPath;
}
else
{
findString = serverPath;
replaceString = clientPath;
}

findString = findString.Replace("//", "/");
replaceString = replaceString.Replace("//", "/");

// these are the attributes that are searched
// for (case sensitive)
string[] tags = new string[]
{
"href",
"src",
"base",
"HREF",
"SRC",
"BASE"
};

// replace all links in the document
foreach (string tag in tags)
{
string prefix = tag + "=\"";
if (content.IndexOf(prefix + findString) > 0)
content = content.Replace(prefix + findString, prefix + replaceString);
}
}
return content;
}

User avatar
Guest
admin - 5/6/2005 9:06:12 PM
   
Re: Different virtual paths
Hi Wiebe,

thank you for this code. Some of our customers use this utility: http://www.mindxpand.be/iisadmin

It allows you to easily configure a separate web site on Windows XP and then you can place Kentico CMS into the root of that web site so that you don't have to solve the issues with different URLs on the local machine and on the server.

Regarding the problem with double slashes - it's usually better to use "~/." instead of "~/". (we have recently fixed several bugs in Kentico CMS 1.6 that appear only when you run the web site in the root folder of the web site - some of them were caused by this expression).

Best Regards,

User avatar
Member
Member
wtijsma - 5/10/2005 9:40:04 AM
   
Re: Different virtual paths
Indeed, I had them as well, the '~/.' is a better solution... Currently I fixed it by just replacing all '//' instances with '/' (too easy)

Thanks

User avatar
Guest
marco - 2/25/2006 3:17:56 PM
   
Re: Different virtual paths
Hi,

I also would like to be flexible in the setting of the virtual path. Is this still the only method to resolve this issue, or is another option available in the new version of KenticoCMS?

User avatar
Guest
admin - 2/27/2006 10:34:48 AM
   
Re: Different virtual paths
Unfortunately, it isn't, since this is a common ASP.NET issue. You still need to use dynamic paths with ResolveUrl("~") method and it's recommended that you use IISAdmin and create the web site locally in a root of the testing web site.

Best Regards,