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; }
|