示例#1
0
        /// <summary>
        /// Generate dynamic encoding javascript codes
        /// </summary>
        /// <param name="pageBasePath">base path of current request page</param>
        /// <returns>Javascript codes</returns>
        string GenerateJsEncoderCodes(
            string pageUrl,
            string pageUrlNoQuery,
            string pagePath,
            string rootUrl)
        {
            string userConfig;
            string reqInfo;
            string cookieNames;
            string locationObject;

            userConfig = string.Format(Consts.ClientContent.JSEncoder_UserConfig,
                                       _UserOptions.EncodeUrl.ToString().ToLower(),
                                       _UserOptions.OrginalUrl.ToString().ToLower(),
                                       _UserOptions.Links.ToString().ToLower(),
                                       _UserOptions.Images.ToString().ToLower(),
                                       _UserOptions.SubmitForms.ToString().ToLower(),
                                       _UserOptions.Frames.ToString().ToLower(),
                                       _UserOptions.Cookies.ToString().ToLower(),
                                       _UserOptions.RemoveScripts.ToString().ToLower(),
                                       _UserOptions.RemoveObjects.ToString().ToLower(),
                                       _UserOptions.TempCookies.ToString().ToLower()
                                       );

            reqInfo = string.Format(Consts.ClientContent.JSEncoder_RequestInfo,
                                    // V5.5b4 BUGFIX: page url should be encoded, it may contain unsecure chars.
                                    HtmlTags.EncodeJavascriptString(pageUrl, true),
                                    HtmlTags.EncodeJavascriptString(pageUrlNoQuery, true),
                                    HtmlTags.EncodeJavascriptString(pagePath, true),
                                    HtmlTags.EncodeJavascriptString(rootUrl, true),
                                    Systems.CookieManager.GetCookieName(pageUrl),
                                    Systems.CookieManager.GetCookieNameExt,
                                    UrlProvider.JoinUrl(UrlProvider.GetAppAbsolutePath(), Consts.FilesConsts.PageDefault_Dynamic),
                                    UrlProvider.GetAppAbsolutePath(),
                                    UrlProvider.GetAppAbsoluteBasePath(),
                                    Consts.FilesConsts.PageDefault_Dynamic,
                                    Consts.Query.Base64Unknowner
                                    );

            // Cookie names
            StringCollection strColl         = Systems.CookieManager.GetAppliedCookieNamesList(pageUrl);
            string           cookieNamesTemp = "";

            for (int i = 0; i < strColl.Count; i++)
            {
                string name = strColl[i];
                cookieNamesTemp += "'" + name + "'";
                if (i != strColl.Count - 1)
                {
                    cookieNamesTemp += ',';
                }
            }
            cookieNames = string.Format(Consts.ClientContent.JSEncoder_AppliedCookieNames,
                                        cookieNamesTemp);

            // Page uri
            Uri pageUri = new Uri(pageUrl);

            locationObject = string.Format(Consts.ClientContent.JSEncoder_RequestLocation,
                                           pageUri.Fragment,     // Hash
                                           pageUri.Authority,    // Host
                                           pageUri.Host,         // Hostname
                                           pageUri.AbsolutePath, // Pathname
                                           pageUri.Query,        // Search
                                           pageUri.Port,         // Port
                                           pageUri.Scheme        // Protocol
                                           );

            StringBuilder result = new StringBuilder();

            try
            {
                // ASProxy encoder variables
                result.Append(Resources.ASProxyJavaScriptTag(userConfig + reqInfo + locationObject + cookieNames, ""));

                // Base64 encoder
                result.Append(Resources.ASProxyJavaScriptTag("", Consts.FilesConsts.JSBase64));

                // ASProxy encoder
                result.Append(Resources.ASProxyJavaScriptTag("", Consts.FilesConsts.JSASProxyEncoder));

                // AJAX wrapper core, Usless since v5.5b4
                // result.Append(Resources.ASProxyJavaScriptTag("", Consts.FilesConsts.JSAJAXWrapperCore));

                return(result.ToString());
            }
            finally
            {
                // release the memory of stringBuilder
                result.Length = 0;
            }
        }