/// <summary>
        /// Determines when to do a redirect.  This is separate to the rewriting process.  The module developer can create any type of Url redirect here, because the entire Url of the original request is passed in.
        /// </summary>
        /// <param name="tabId">Identified TabId, if known.  -1 if no valid tabid identified.</param>
        /// <param name="portalid">Identified portalId.</param>
        /// <param name="httpAlias">Identified httpAlias of the request.</param>
        /// <param name="requestUri">The original requested Url</param>
        /// <param name="queryStringCol">The querystring collection of the original request</param>
        /// <param name="options">The friendly url options that currently apply.</param>
        /// <param name="redirectLocation">Out parameter that shows where to redirect to.</param>
        /// <param name="messages">List of messages for debug purposes.  Add to this list to help debug your module.</param>
        /// <returns>true if 301 redirect is required, false if not.  If true, the redirectLocation value must be a valid fully qualified Url.</returns>
        public override bool CheckForRedirect(int tabId, int portalid, string httpAlias, Uri requestUri, System.Collections.Specialized.NameValueCollection queryStringCol, iFinity.DNN.Modules.UrlMaster.FriendlyUrlOptions options, out string redirectLocation, ref List<string> messages)
        {
            bool doRedirect = false;
            redirectLocation = "";//set blank location
            //compare to known pattern of old Urls
            //could be in old /itemid/xx format - if so, we want to redirect it

            string urlWithoutAlias = requestUri.AbsoluteUri.Replace(httpAlias, "").Replace(requestUri.Scheme + "://","");
            if(urlWithoutAlias.StartsWith("/"))
            {
                urlWithoutAlias = urlWithoutAlias.Substring(1);
            }

            //Check Database / Cache for the key.
            //Redirect if key found.

            foreach (VanityUrlInfo urlInfo in VanityUrlController.GetVanityURLs(portalid))
            {
                if(urlInfo.VanityUrl.ToLower()==urlWithoutAlias.ToLower())
                {
                    if ((urlInfo.ActiveStartDate == null || urlInfo.ActiveStartDate < DateTime.Now) &&
                        (urlInfo.ActiveEndDate == null || urlInfo.ActiveEndDate > DateTime.Now))
                    {

                        doRedirect = true;
                        redirectLocation = requestUri.Scheme + "://" + httpAlias + urlInfo.RedirectUrl;
                        VanityUrlController.UpdateLastAccessedDate(urlInfo, portalid);
                        break;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return doRedirect;
        }
        /// <summary>
        /// This method is used by the Url Master Url Rewriting process.  The purpose of this method is to take the supplied array of Url parameters, and transform them into a module-specific querystring for the underlying re-written Url.
        /// </summary>
        /// <param name="urlParms">The array of parameters found after the DNN page path has been identified.  No key/valeu pairs are identified, the parameters are converted from the /key/value/key2/value2 format into [key,value,key2,value2] format.</param>
        /// <param name="tabId">TabId of identified DNN page.</param>
        /// <param name="portalId">PortalId of identified DNN portal.</param>
        /// <param name="options">The current Friendly Url options being used by the module.</param>
        /// <param name="cultureCode">Identified language/culture code, if supplied.</param>
        /// <param name="portalAlias">Identified portalAlias object for the request.</param>
        /// <param name="messages">List of debug messages.  Add to this list to help debug your module.  Can be viewed in the reponse headers of the request, or in the 'Test Url Rewriting' section of the Url Master module.</param>
        /// <param name="status">Out parameter, returns the Http status of the request.  May be 200,301,302, or 404.  For normal rewriting, return a 200 value.</param>
        /// <param name="location">If a 301 or 302 is returned in the status parameter, then this must contain a valid redirect location.  This should be a fully-qualified Url.</param>
        /// <returns>The querystring to be used for rewriting the Url. NOTE: doesn't need to include the tabid if the tabid parameter is &gt; -1</returns>
        public override string TransformFriendlyUrlToQueryString(string[] urlParms, int tabId, int portalId, iFinity.DNN.Modules.UrlMaster.FriendlyUrlOptions options, string cultureCode, DotNetNuke.Entities.Portals.PortalAliasInfo portalAlias, ref List<string> messages, out int status, out string location)
        {
            //store local options variable
            _options = options;
            //initialise results and output variables
            string result = ""; status = 200; //OK
            location = null; //no redirect location
            if (messages == null) messages = new List<string>();

            return result;
        }
 /// <summary>
 /// The Change Friendly Url method is called for every Url generated when a page is generated by DotNetNuke.  This call sits 'underneath' the 'NavigateUrl' call in DotNetNuke.
 /// Whenever your module calls NavigateUrl, this method will be also called.  In here, the module developer should modify the friendlyUrlPath to the final state required.
 /// However, because this call is used for all Urls on the page, not just those generated by the target module, some type of high-level filter should be used to make sure only
 /// the module Urls are modified.
 /// </summary>
 /// <param name="tab">Current Tab</param>
 /// <param name="friendlyUrlPath">Current Friendly Url Path after going through the Friendly Url Generation process of the Url Master module.</param>
 /// <param name="options">The options currently applying to Urls in this portal (space replacement, max length, etc)</param>
 /// <param name="cultureCode">The culture code being used for this Url (if supplied, may be empty)</param>
 /// <param name="endingPageName">The page name the Url has been called with. Normally default.aspx, but may be different for some modules.</param>
 /// <param name="useDnnPagePath">Out parameter to be set by the module.  If true, the path of the DNN page will be in the Url (ie /pagename).  If false, this part of the Url will be removed.</param>
 /// <param name="messages">List of debug messages.  Add any debug information to this collection to help debug your provider.  This can be seen in the repsonse headers, and also in the 'test Url Rewrite' page in the Url Master module.</param>
 /// <returns>System.String.</returns>
 public override string ChangeFriendlyUrl(DotNetNuke.Entities.Tabs.TabInfo tab, string friendlyUrlPath, iFinity.DNN.Modules.UrlMaster.FriendlyUrlOptions options, string cultureCode, ref string endingPageName, out bool useDnnPagePath, ref List<string> messages)
 {
     _options = options;//keep local copy of options
     //set default values for out parameters
     useDnnPagePath = true;
     if (messages == null) messages = new List<string>();
     //check if we want to try and modify this Url
     //first check to see if this Url is an 'edit' Url - something that loads a module-specific page.
     //we don't want to mess with these, because they're always permissions based Urls and thus
     //no need to be friendly
     return friendlyUrlPath;
 }