예제 #1
0
 public static string Decrypt(Site site, string cryptedString)
 {
     if (String.IsNullOrEmpty(cryptedString))
     {
         return cryptedString;
     }
     var key = GetKey(site.AsActual());
     DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
     MemoryStream memoryStream = new MemoryStream
             (Convert.FromBase64String(cryptedString));
     CryptoStream cryptoStream = new CryptoStream(memoryStream,
         cryptoProvider.CreateDecryptor(key, key), CryptoStreamMode.Read);
     StreamReader reader = new StreamReader(cryptoStream);
     return reader.ReadToEnd();
 }
예제 #2
0
        public static IHtmlString WrapperUrl(string url, Site site, FrontRequestChannel channel, bool? requireSSL)
        {
            if (string.IsNullOrEmpty(url))
            {
                return new HtmlString(url);
            }
            var applicationPath = HttpContext.Current.Request.ApplicationPath.TrimStart(new char[] { '/' });
            if (!url.StartsWith("/") && !string.IsNullOrEmpty(applicationPath))
            {
                url = "/" + applicationPath + "/" + url;
            }

            var sitePath = site.AsActual().SitePath;
            if (channel == FrontRequestChannel.Debug || channel == FrontRequestChannel.Design || channel == FrontRequestChannel.Unknown)
            {
                sitePath = SiteHelper.PREFIX_FRONT_DEBUG_URL + site.FullName;
            }
            var urlSplit = url.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            IEnumerable<string> urlPaths = urlSplit;
            if (!string.IsNullOrEmpty(sitePath))
            {
                if (urlSplit.Length > 0 && applicationPath.EqualsOrNullEmpty(urlSplit[0], StringComparison.OrdinalIgnoreCase))
                {
                    urlPaths = new string[] { applicationPath, sitePath }.Concat(urlSplit.Skip(1));
                }
                else
                {
                    urlPaths = new string[] { sitePath }.Concat(urlSplit);
                }
            }
            var endWithSlash = url.EndsWith("/");
            url = "/" + string.Join("/", urlPaths.ToArray());
            if (endWithSlash && !url.EndsWith("/"))
            {
                url = url + "/";
            }

            #region SSL
            if (requireSSL.HasValue)
            {
                if (channel == FrontRequestChannel.Host || channel == FrontRequestChannel.HostNPath)
                {
                    if (HttpContext.Current.Request.IsSecureConnection)
                    {
                        //if (!requireSSL.Value)
                        //{
                        //    url = "http://" + HttpContext.Current.Request.Url.Host + url;
                        //}
                    }
                    else if (requireSSL.Value)
                    {
                        url = "https://" + HttpContext.Current.Request.Url.Host + url;
                    }
                }
            }

            #endregion

            return new HtmlString(url);
        }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PageRequestContext" /> class.
        /// </summary>
        /// <param name="controllerContext">The controller context.</param>
        /// <param name="rawSite">The raw.</param>
        /// <param name="site">The site.</param>
        /// <param name="page">The page.</param>
        /// <param name="requestChannel">The request channel.</param>
        /// <param name="pageRequestUrl">The page request url with out page virtual path.</param>
        public PageRequestContext(ControllerContext controllerContext, Site rawSite, Site site, Page rawPage, Page page,
            FrontRequestChannel requestChannel, string pageRequestUrl)
        {
            RouteValues = new RouteValueDictionary();

            this.ControllerContext = controllerContext;

            var httpContext = HttpContext.Current;

            this.RawSite = rawSite;
            this.RawPage = rawPage;
            this.Site = site.AsActual();
            this.Page = page.AsActual();
            this.RequestChannel = requestChannel;

            this.AllQueryString = new NameValueCollection();
            var queryString = httpContext.Request.QueryString;
            foreach (var key in queryString.AllKeys)
            {
                var value = queryString[key];
                if (!string.IsNullOrEmpty(value))
                {
                    AllQueryString[HttpUtility.HtmlEncode(key)] = HttpUtility.HtmlEncode(value);
                }
                else
                {
                    AllQueryString[HttpUtility.HtmlEncode(key)] = value;
                }

            }

            if (string.IsNullOrEmpty(pageRequestUrl))
            {
                pageRequestUrl = "/";
            }

            HttpContextBase pageContext = new PageHttpContenxt(httpContext,
                new PageHttpRequest(httpContext.Request, UrlUtility.Combine("~", pageRequestUrl), ""));
            var routeData = page.Route.ToMvcRoute().GetRouteData(pageContext);

            if (routeData != null)
            {
                RouteValues = routeData.Values;
                //Combine page parameters to [QueryString].
                foreach (var item in RouteValues)
                {
                    if (item.Value != null)
                    {
                        AllQueryString[item.Key] = item.Value.ToString();
                    }
                }
            }

            var moduleUrl = AllQueryString[ModuleUrlContext.ModuleUrlSegment];
            var modulePositions = page.PagePositions.Where(it => it is ModulePosition || it is ProxyPosition).Count();
            ModuleUrlContext = new ModuleUrlContext(this, moduleUrl, modulePositions);
        }