Пример #1
0
        public void DoParse(string rawUrl, UrlFormat urlFormat)
        {
            int appUrlLength = Globals.AppRoot.Length + 1;
            int queryIndex;

            string main, originalMain, query;
            string nameLink = null;

            int nameLinkIndex = rawUrl.IndexOf('#');

            if (nameLinkIndex >= 0)
            {
                nameLink = rawUrl.Substring(nameLinkIndex);
                rawUrl   = rawUrl.Remove(nameLinkIndex);
            }

            switch (urlFormat)
            {
            case UrlFormat.Aspx:
            case UrlFormat.Html:
                queryIndex = rawUrl.IndexOf('?', appUrlLength);
                if (queryIndex == -1)
                {
                    originalMain = rawUrl.Substring(appUrlLength, rawUrl.Length - appUrlLength);
                    query        = string.Empty;
                }
                else
                {
                    originalMain = rawUrl.Substring(appUrlLength, queryIndex - appUrlLength);
                    query        = rawUrl.Substring(queryIndex);
                }
                main = originalMain.Remove(originalMain.Length - 5);
                break;

            default:


                if (urlFormat == UrlFormat.Query)
                {
                    int rawLength = rawUrl.Length;

                    if (rawUrl[appUrlLength] == '?')
                    {
                        originalMain = "?";
                        appUrlLength++;
                    }

                    else if (rawLength > appUrlLength + 12 && rawUrl[appUrlLength + 12] == '?' && string.Compare(rawUrl.Substring(appUrlLength, 7), "default", true) == 0)
                    {
                        originalMain  = "?";
                        appUrlLength += 13;
                    }

                    else if (rawLength > appUrlLength + 10 && rawUrl[appUrlLength + 10] == '?' && string.Compare(rawUrl.Substring(appUrlLength, 5), "index", true) == 0)
                    {
                        originalMain  = "?";
                        appUrlLength += 11;
                    }

                    else if (rawLength == appUrlLength)
                    {
                        this.m_OriginalMain = string.Empty;
                        this.m_Main         = string.Empty;
                        this.m_QueryString  = string.Empty;
                        return;
                    }
                    else
                    {
                        originalMain = string.Empty;
                    }
                }
                else
                {
                    originalMain = string.Empty;
                }

                queryIndex = rawUrl.IndexOf('?', appUrlLength);
                if (queryIndex == -1)
                {
                    main  = rawUrl.Substring(appUrlLength, rawUrl.Length - appUrlLength);
                    query = string.Empty;
                }
                else
                {
                    main  = rawUrl.Substring(appUrlLength, queryIndex - appUrlLength);
                    query = rawUrl.Substring(queryIndex);
                }
                originalMain += main;
                break;
            }

            if (main.Length > 5 && main[main.Length - 5] == '.' &&
                (StringUtil.EndsWithIgnoreCase(main, ".aspx") || StringUtil.EndsWithIgnoreCase(main, ".html"))
                )
            {
                main = main.Remove(main.Length - 5);
            }

            if (main.Length == 0 || (main.Length == 5 && string.Compare(main, "index", true) == 0))
            {
                main = "default";

                if (urlFormat == UrlFormat.Query)
                {
                    originalMain = "?default";
                }
            }
            else if (urlFormat == UrlFormat.Query && string.Compare(main, "default", true) == 0)
            {
                originalMain = "?default";
            }

            //if (originalMain.Length == 0 || )

            this.m_OriginalMain = originalMain;
            this.m_Main         = main;
            this.m_QueryString  = query;

            if (nameLink != null)
            {
                this.m_NameLink = nameLink;
            }
        }