public Uri HandleRequest(string profileName, HttpWebRequest request)
        {
            if (string.IsNullOrEmpty(profileName))
            {
                profileName = DefaultProfileName;
            }
            var profile = _profileCache.GetProfile(profileName);
            if (profile == null)
            {
                var profilepath = Path.Combine(_profileRootPath, profileName + "\\");

                lock (ProfileCreatorLock)
                {
                    profile = _profileCache.GetProfile(profileName);
                    if (profile == null)
                    {
                        profile = new Profile();
                        if (Directory.Exists(profilepath))
                        {
                            var profileRewriterEngine = new MicrosoftRewriterEngine(profilepath);
                            profileRewriterEngine.Init();
                            profile.RewriterEngine = profileRewriterEngine;

                            Logger.InfoFormat("Profile loaded for {0}", profileName);
                        }
                        else
                        {
                            Logger.InfoFormat("No profile for {0}", profileName);
                        }

                        _profileCache.AddProfile(profileName, profile);
                    }
                }
            }

            if (profile.RewriterEngine == null)
            {
                return null;
            }

            var httpContext = new HttpContext(request);

            var rewrittenUrl = profile.RewriterEngine.RunRules(httpContext);

            return rewrittenUrl;
        }
 public void AddProfile(string profileName, Profile profile)
 {
     var cacheItemPolicy = new CacheItemPolicy();
     Cache.AddOrGetExisting(profileName, profile, cacheItemPolicy, RegionName);
 }