コード例 #1
0
        /// <summary>
        /// url의 파라미터 값을 urlEncode
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string ParamUrlEncode(string url)
        {
            if (url.IndexOf("?") < 0)
            {
                return(url);
            }

            string[] param = GetParams(url);

            System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();

            foreach (string pr in param)
            {
                string[] p = StringTool.Split(pr, '=');

                if (p.Length < 2)
                {
                    continue;
                }

                if (string.IsNullOrEmpty(p[0]))
                {
                    continue;
                }

                stringBuilder.AppendFormat("{0}={1}&", p[0], AntiXssTool.UrlEncode((p.Length > 1) ? p[1] : string.Empty));
            }

            return(stringBuilder.ToString());
        }
コード例 #2
0
        /// <summary>
        /// url의 파람값들을 collection 값에 있는 파람값들로 교체한다.
        /// </summary>
        /// <param name="url"></param>
        /// <param name="cols"></param>
        /// <param name="isEnc">UrlEncode 여부</param>
        /// <returns></returns>
        public static string ReplaceParamValue(string url, NameValueCollection cols, bool isEnc)
        {
            if (url.IndexOf("?") < 0)
            {
                return(url);
            }

            var ps = GetParam(url);

            url = GetUri(url);

            for (int i = 0; i < ps.Count; i++)
            {
                foreach (string ckey in cols.Keys)
                {
                    if (string.IsNullOrEmpty(ckey))
                    {
                        continue;
                    }

                    if (ps.GetKey(i).ToUpper().Equals(ckey.ToUpper()))
                    {
                        ps[ps.GetKey(i)] = cols[ckey];
                        break;
                    }
                }
            }

            var p = new StringBuilder();

            foreach (string k in ps.Keys)
            {
                p.AppendFormat("{0}={1}&", k, isEnc ? AntiXssTool.UrlEncode(ps[k]) : ps[k]);
            }

            return(UrlParamConcat(url, p.ToString()));
        }
コード例 #3
0
        /// <summary>
        /// 메시지 출력
        /// page 가 null 이 아니면 RegisterStartupScript 로 스크립트 추가되어지므로 호출후 Response.End()등으로 실행중지시 출력되어지지 않습니다.
        /// </summary>
        /// <param name="messageBoxDisplayKind">출력타입</param>
        /// <param name="title">메시지 캡션</param>
        /// <param name="text">메시지</param>
        /// <param name="messageType">메시지타입</param>
        /// <param name="messageButton">버튼타입</param>
        /// <param name="page">렌더링되는 페이지</param>
        /// <param name="returnUrl">메시지출력후 이동할 url</param>
        /// <param name="endResponse">프로세스 종료여부</param>
        public static void MessageBox(MessageBoxDisplayKind messageBoxDisplayKind,
                                      string title,
                                      string text,
                                      MessageType messageType      = MessageType.Normal,
                                      MessageButtons messageButton = MessageButtons.Ok,
                                      System.Web.UI.Page page      = null,
                                      string returnUrl             = "",
                                      bool endResponse             = true)
        {
            switch (messageBoxDisplayKind)
            {
            case MessageBoxDisplayKind.Page:

                var httpResponse = HttpContext.Current.Response;
                var param        = string.Format("Title={0}&Content={1}&MessageType={2}&MessageButton={3}&ReturnUrl={4}",
                                                 title.UrlEncode(), text.UrlEncode(), (int)messageType, (int)messageButton, returnUrl.UrlEncode());
                var url = UrlParamConcat(AppSettings.MessageBoxUrl, param);
                httpResponse.Redirect(url, endResponse);
                return;

            default:

                #region

                StringBuilder buffer = new StringBuilder();
                try
                {
                    buffer.Append(@"alert(");
                    buffer.Append(AntiXssTool.JavaScriptEncode((title.IsNotWhiteSpace() ? "[" + title + "]\n\n" : string.Empty) + text));
                    buffer.Append(@");");

                    // Alert이고 닫기 타입이 Close 이면 창을 닫는다.
                    if (messageButton == MessageButtons.Close)
                    {
                        buffer.Append(SR.CloseWindowJavascript);
                    }
                    else if (returnUrl.IsNotWhiteSpace())
                    {
                        buffer.AppendFormat("window.location.href={0};", AntiXssTool.JavaScriptEncode(returnUrl));
                    }

                    if (page != null)
                    {
                        //이미 추가되었다면
                        if (page.ClientScript.IsStartupScriptRegistered(page.GetType(), page + "_MessageBox"))
                        {
                            ScriptManager.RegisterStartupScript(page, page.GetType(), page + "_MessageBox", buffer.ToString(), true);
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(page, page.GetType(), page + "_MessageBox", buffer.ToString(), true);
                        }
                    }
                    else
                    {
                        HttpContext.Current.Response.Output.Write(WrapScriptTag(buffer.ToString()));
                    }
                }
                finally
                {
                    buffer = null;
                }

                #endregion

                break;
            }
        }
コード例 #4
0
        public void EncodeJavascript()
        {
            var encoded = AntiXssTool.JavaScriptEncode("javascript:alert('abc');");

            Console.WriteLine(encoded);
        }