/// <summary>
        /// Replace the replacement parameter {MediaObjectRelativeUrlNoHandler} with an URL that is relative to the media objects
        /// directory and which points directly to the media object (ex: /videos/birthdayvideo.wmv). Note
        /// that using this parameter completely bypasses the HTTP handler that normally streams the media object. The consequence
        /// is that there is no security check when the media object request is made and no watermarks are applied, even if
        /// watermark functionality is enabled. This option should only be used when it is not important to restrict access to
        /// the media objects.
        /// </summary>
        /// <param name="htmlOutput">A string representing the HTML that will be sent to the browser for the current media object.
        /// It is based on the template stored in the media template table.</param>
        /// <returns>Returns the htmlOutput parameter with the {MediaObjectRelativeUrlNoHandler} string replaced by the URL to the media
        /// object.</returns>
        /// <exception cref="GalleryServerPro.Events.CustomExceptions.BusinessException">Thrown when the current media object's
        /// physical path does not start with the same text as AppSetting.Instance.MediaObjectPhysicalPath.</exception>
        /// <remarks>Typically this parameter is used instead of {MediaObjectAbsoluteUrlNoHandler} when the media objects directory
        /// is outside of the web application. If the user wants to allow direct access to the media objects using this parameter,
        /// she must first configure the media objects directory as a virtual directory in IIS. Then the path to this virtual directory
        /// must be manually entered into one or more HTML templates, so that it prepends the relative url returned from this method.</remarks>
        /// <example>If the media objects directory has been set to D:\media and a virtual directory named gallery has been configured
        /// in IIS that is accessible via http://yoursite.com/gallery, then you can configure the HTML template like this:
        /// HtmlTemplate="&lt;a href=&quot;http://yoursite.com/gallery{MediaObjectRelativeUrlNoHandler}&quot;&gt;Click to open&lt;/a&gt;"
        /// </example>
        private string ReplaceMediaObjectRelativeUrlNoHandlerParameter(string htmlOutput)
        {
            var moPath = Factory.LoadGallerySetting(GalleryObject.GalleryId).FullMediaObjectPath;

            if (!MediaObjectPhysicalPath.StartsWith(moPath, StringComparison.OrdinalIgnoreCase))
            {
                throw new BusinessException(String.Format(CultureInfo.CurrentCulture, "Expected this.MediaObjectPhysicalPath (\"{0}\") to start with AppSetting.Instance.MediaObjectPhysicalPath (\"{1}\"), but it did not.", MediaObjectPhysicalPath, moPath));
            }

            var relativePath = MediaObjectPhysicalPath.Remove(0, moPath.Length).Trim(new[] { System.IO.Path.DirectorySeparatorChar });

            relativePath = Utils.UrlEncode(relativePath, '\\');

            var relativeUrl = String.Concat("/", relativePath.Replace("\\", "/"));

            return(htmlOutput.Replace("{MediaObjectRelativeUrlNoHandler}", relativeUrl));
        }
        /// <summary>
        /// Replace the replacement parameter {MediaObjectAbsoluteUrlNoHandler} with an URL that points directly to the media object
        /// (ex: /gallery/videos/birthdayvideo.wmv). A BusinessException is thrown if the media objects directory is not
        /// within the web application directory. Note that using this parameter completely bypasses the HTTP handler that
        /// normally streams the media object. The consequence is that there is no security check when the media object request
        /// is made and no watermarks are applied, even if watermark functionality is enabled. This option should only be
        /// used when it is not important to restrict access to the media objects.
        /// </summary>
        /// <param name="htmlOutput">A string representing the HTML that will be sent to the browser for the current media object.
        /// It is based on the template stored in the media template table.</param>
        /// <returns>Returns the htmlOutput parameter with the {MediaObjectAbsoluteUrlNoHandler} string replaced by the URL to the media
        /// object.</returns>
        /// <exception cref="GalleryServerPro.Events.CustomExceptions.BusinessException">Thrown when the media objects
        /// directory is not within the web application directory.</exception>
        private string ReplaceMediaObjectAbsoluteUrlNoHandlerParameter(string htmlOutput)
        {
            var appPath = AppSetting.Instance.PhysicalApplicationPath;

            if (!MediaObjectPhysicalPath.StartsWith(appPath, StringComparison.OrdinalIgnoreCase))
            {
                throw new BusinessException(String.Format(CultureInfo.CurrentCulture, "Expected this.MediaObjectPhysicalPath (\"{0}\") to start with AppSetting.Instance.PhysicalApplicationPath (\"{1}\"), but it did not. If the media objects are not stored within the Gallery Server Pro web application, you cannot use the MediaObjectAbsoluteUrlNoHandler replacement parameter. Instead, use MediaObjectRelativeUrlNoHandler and specify the virtual path to your media object directory in the HTML template. For example: HtmlTemplate=\"<a href=\"{{HostUrl}}/media{{MediaObjectRelativeUrlNoHandler}}\">Click to open</a>\"", MediaObjectPhysicalPath, appPath));
            }

            var relativePath = MediaObjectPhysicalPath.Remove(0, appPath.Length).Trim(new[] { System.IO.Path.DirectorySeparatorChar });

            relativePath = Utils.UrlEncode(relativePath, '\\');

            var directUrl = String.Concat(Utils.UrlEncode(AppRoot, '/'), "/", relativePath.Replace("\\", "/"));

            return(htmlOutput.Replace("{MediaObjectAbsoluteUrlNoHandler}", directUrl));
        }