Ejemplo n.º 1
0
        private string GetUrl(INavigatable node, HttpContextBase httpContext, string applicationRoot)
        {
            string url = urlGenerator.Generate(httpContext.RequestContext(), node);

            if (!string.IsNullOrEmpty(url))
            {
                if (!url.StartsWith("/", StringComparison.Ordinal))
                {
                    url = "/" + url;
                }

                url = applicationRoot + url;
            }

            return url;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Enables a JsHttpHandler object to process of requests.
        /// </summary>
        /// <param name="context">The context.</param>
        public override void ProcessRequest(HttpContextBase context)
        {
            var languageId = EngineContext.Current.Resolve<IWorkContext>().WorkingLanguage.RowId;

            if (!languageId.IsEmpty())
            {
                HttpResponseBase response = context.Response;

                // set hte json object
                JsonCulture jsonCulture = new JsonCulture(languageId);

                // set the content type
                response.ContentType = "text/javascript";

                // create the app engine i18n script
                string jsScript = "$.extend(appEngine, {i18n: " + jsonCulture.ToJsonString() + "});";

                var urlHelper   = new UrlHelper(context.RequestContext());
                JsonUrl jsonUrl = new JsonUrl(urlHelper);

                // implement the urls
                jsScript += "$.extend(appEngine, {path: " +  jsonUrl.ToJsonString() + "});";

                if (!string.IsNullOrEmpty(jsScript))
                {
                    _httpResponseCompressor.Compress(context);

                    // Write
                    using (StreamWriter sw = new StreamWriter((response.OutputStream)))
                    {
                        sw.Write(jsScript);
                    }

                    // cache the contents
                    _httpResponseCacher.Cache(context, TimeSpan.FromDays(7));
                }
            }
        }