微軟説:"Maximum URL length is 2,083 characters in Internet Explorer"

我們在Pricing系統開發中挑戰了一下這個長度,結果以失敗告終!......


問題描述:系統中通過一個QLookUp選取Vendor相關信息,包括vendor code, vendor name, vendor site, currency, trade term, ship way, tax七項信息。把處理這些信息的SQL語句和JS語句通過URL傳到QLookUPSearchPage.aspx頁面來查找數據時,因為URL太長而出錯!


QLookUp:

簡單來説,它是一個用户控件,通過URL把SQL語句和頁面要執行的JS語句傳到QLookUPSearchPage.aspx這個頁面來查到相應的數據,並返回給調用頁面。


Pricing 系統廣泛並深入的應用了QLookUp控件。如下圖Vendor Code。


點出來的頁面如下:


因為當點選Vendor Code時還會把QLookUp查出來的數據賦給旁邊的其它五個控件(Vendor Name....Ship Way),所以它的CustomerFunction屬性就會很長:

<uc1:QLookUp ID="QLookUpVendorNew" runat="server" AllowOnBlurEvent="true" OnQLookUPSelected="QLookUpVendorNew_Selected" ServiceMethod="GetVendorCodeList" CustomerFunction="if(clear!=1){objTextBoxText.value=arrayValue[1];document.getElementById('HiddenVendorIDNew').value=arrayValue[0];document.getElementById('QTextBoxVendorNameNew').value=arrayValue[2];document.getElementById('QTextBoxVendorSiteNew').value=arrayValue[3];if(arrayValue[6].length > 0){var DropDownListCurrencyNew = document.getElementById('DropDownListCurrencyNew'); for(i=0;i<DropDownListCurrencyNew.options.length;i++){if(DropDownListCurrencyNew.options[i].text==arrayValue[6]){DropDownListCurrencyNew.options[i].selected = true;}}}  if(arrayValue[4].length > 0){document.getElementById('DropDownListTradeTermNew').value=arrayValue[4];} else{document.getElementById('DropDownListTradeTermNew').options[0].selected=true;}  if(arrayValue[5].length > 0){document.getElementById('DropDownListShipWayNew').value=arrayValue[5];} else{document.getElementById('DropDownListShipWayNew').options[0].selected=true;} } else {document.getElementById('HiddenVendorIDNew').value='';document.getElementById('QTextBoxVendorNameNew').value='';document.getElementById('QTextBoxVendorSiteNew').value='';document.getElementById('DropDownListCurrencyNew').options[0].selected=true;document.getElementById('DropDownListTradeTermNew').options[0].selected=true;document.getElementById('DropDownListShipWayNew').options[0].selected=true;}" alt="required::MSG500014::QButtonAdd" TextBoxCss="QTextBox" Width="160px" WindowTitle="Select Vendor" />

為了看起來清晰點,我把CustomerFunction提出來,格式化後如下:


CustomerFunction = "

if(clear!=1)

{

    objTextBoxText.value=arrayValue[1];

    document.getElementById('HiddenVendorIDNew').value=arrayValue[0];

    document.getElementById('QTextBoxVendorNameNew').value=arrayValue[2];

    document.getElementById('QTextBoxVendorSiteNew').value=arrayValue[3];

    if(arrayValue[6].length>0)

    {

        var DropDownListCurrencyNew=document.getElementById('DropDownListCurrencyNew');

        for(i=0;i<DropDownListCurrencyNew.options.length;i++)

        {

            if(DropDownListCurrencyNew.options[i].text==arrayValue[6])

            {

                DropDownListCurrencyNew.options[i].selected=true;

                

            }

        }

    }if(arrayValue[4].length>0)

    {

        document.getElementById('DropDownListTradeTermNew').value=arrayValue[4];

        

    }else  
    {

        document.getElementById('DropDownListTradeTermNew').options[0].selected=true;

        

    }if(arrayValue[5].length>0)

    {

        document.getElementById('DropDownListShipWayNew').value=arrayValue[5];

        

    }else  
    {

        document.getElementById('DropDownListShipWayNew').options[0].selected=true;

        

    }

}else  
{

    document.getElementById('HiddenVendorIDNew').value='';

    document.getElementById('QTextBoxVendorNameNew').value='';

    document.getElementById('QTextBoxVendorSiteNew').value='';

    document.getElementById('DropDownListCurrencyNew').options[0].selected=true;

    document.getElementById('DropDownListTradeTermNew').options[0].selected=true;

    document.getElementById('DropDownListShipWayNew').options[0].selected=true;

    

}"

我們來看看點擊QLookUp的Search img後,彈出來的QLookUPSearchPage.aspx頁面的URL是什麼:


http://localhost/Pricing/Web/Public/QLookUPSearchPage.aspx?SQL=+WOeqS2Mk/H6E9ICwIOpVbfgAjIPH2onkkRF7fO6kaqZMiq7gRww2LfgAjIPH2onb0G0aFlDKnaVkj5ZYTna9yDKAZJIz8t1GzKRU95Ah7BZ9czLL/8qv94OjoxTQh3qpAIlrIFYcgI/yWSRJXF+z0WkMLZGBidybjtuO86fXa/6zGD5BBrbqWLysS4RIoiQ/Oq2RKy/Ajodoh7HD8ZKV1oFf7uPqCGstAVtzlVyUgjRZefLedBftM8UdZ8W+v33hsuJ6UTHjFEt8ANGdu0TZwypvrgOaoLbUqMWW37vSb1h4RbPScczZKhU88sr+56rVETs2B/XEur5ykVwvKf+1Q==&DataSource=9lDQbyO73rk=&ReturnClientID=QLookUpVendorNew&DataSourceType=EPS&WindowTitle=Select Vendor&CustomerFunction=if(clear!=1){objTextBoxText.value=arrayValue[1];document.getElementById('HiddenVendorIDNew').value=arrayValue[0];document.getElementById('QTextBoxVendorNameNew').value=arrayValue[2];document.getElementById('QTextBoxVendorSiteNew').value=arrayValue[3];if(arrayValue[6].length > 0){var DropDownListCurrencyNew = document.getElementById('DropDownListCurrencyNew'); for(i=0;i<DropDownListCurrencyNew.options.length;i!!!lionel!!!!!!lionel!!!){if(DropDownListCurrencyNew.options[i].text==arrayValue[6]){DropDownListCurrencyNew.options[i].selected = true;}}}  if(arrayValue[4].length > 0){document.getElementById('DropDownListTradeTermNew').value=arrayValue[4];} else{document.getElementById('DropDownListTradeTermNew').options[0].selected=true;}  if(arrayValue[5].length > 0){document.getElementById('DropDownListShipWayNew').value=arrayValue[5];} else{document.getElementById('DropDownListShipWayNew').options[0].selected=true;} } else {document.getElementById('HiddenVendorIDNew').value='';document.getElementById('QTextBoxVendorNameNew').value='';document.getElementById('QTextBoxVendorSiteNew').value='';document.getElementById('DropDownListCurrencyNew').options[0].selected=true;document.getElementById('DropDownListTradeTermNew').options[0].selected=true;document.getElementById('DropDownListShipWayNew').options[0].selected=true;}

數了一下:1857個字符。OK,截止目前,一切正常。


但是,新的需求來了,頁面上要加Tax, 值也是從QLookUp中和Vendor Code一起選出來。

不用多想,肯定是往SQL和CustomerFunction兩個屬性裏繼續加。

但是加上以後就發現QLookUp擺工了,選不過來數據了。反覆的Check也沒發現SQL和CustomerFunction有什麼語法錯誤。給CustomerFunction中加了一個alert(''), 竟然放到任何地方都不彈出Message。奇怪...?

把新加的所有內容全部去掉,還原到上面那樣就沒問題。

最後把Lionel同學拉過過一起研究,他説了一句“難道是URL太長了?”。

嗯?URL長度還有限制?先測試一下再説。把所有新加的內容一點點去掉,到某一點時,發現玄機:

給CustomerFunction中加一個alert('B'),      有問題;

把alert('B')改成var a;                                  沒問題了

再把var a改成var a; var b;                          有問題


很明顯,確實是CustomerFunction的長度導致了URL過長,從而引發了這個問題。


最後來Check一下有問題的URL:

http://localhost/Pricing/Web/Public/QLookUPSearchPage.aspx?SQL=+WOeqS2Mk/H6E9ICwIOpVbfgAjIPH2onkkRF7fO6kaqZMiq7gRww2LfgAjIPH2onb0G0aFlDKnaVkj5ZYTna9yDKAZJIz8t1GzKRU95Ah7BZ9czLL/8qv94OjoxTQh3qpeffefefeAIlrIFYcgI/yWSRJXF+z0WkMLZGBidybjtuO86fXa/6zGD5BBrbqWLysS4RIoiQ/Oq2RKy/Ajodoh7HD8ZKV1oFDFDGEdfwHBDFDFewf7uPqCGstAVtzlVyUgjRZefLedBftM8UdZ8W+v33hsuJ6UTHjFEt8ANGdu0TZwypvrgOaoLbUqMWW37vSb1h4RbPScczZKhU88sr+56rVETs2Bwrwr2324545322dfdf34t5Ggsde56rerFfdfytDFDFF85684hhhfhfghfjfn/XEur5ykVwvKf+1Q==&DataSource=9lDQbyO73rk=&ReturnClientID=QLookUpVendorNew&DataSourceType=EPS&WindowTitle=Select Vendor&CustomerFunction=if(clear!=1){ objTextBoxText.value=arrayValue[1]+' '+arrayValue[2];document.getElementById('HiddenVendorIDNew').value=arrayValue[0];document.getElementById('QTextBoxVendorNameNew').value=arrayValue[2];document.getElementById('QTextBoxVendorSiteNew').value=arrayValue[3]; document.getElementById('QTextBoxVendorTaxNew').value=arrayValue[7];if(arrayValue[6].length > 0){var DropDownListCurrencyNew = document.getElementById('DropDownListCurrencyNew'); for(i=0;i<DropDownListCurrencyNew.options.length;i!!!lionel!!!!!!lionel!!!){if(DropDownListCurrencyNew.options[i].text==arrayValue[6]){DropDownListCurrencyNew.options[i].selected = true;}}}  if(arrayValue[4].length > 0){document.getElementById('DropDownListTradeTermNew').value=arrayValue[4];} else{document.getElementById('DropDownListTradeTermNew').options[0].selected=true;}  if(arrayValue[5].length > 0){document.getElementById('DropDownListShipWayNew').value=arrayValue[5];} else{document.getElementById('DropDownListShipWayNew').options[0].selected=true;} } else {document.getElementById('HiddenVendorIDNew').value='';document.getElementById('QTextBoxVendorNameNew').value=''; document.getElementById('QTextBoxVendorTaxNew').value=’’;document.getElementById('QTextBoxVendorSiteNew').value='';document.getElementById('DropDownListCurrencyNew').options[0].selected=true;document.getElementById('DropDownListTradeTermNew').options[0].selected=true;document.getElementById('DropDownListShipWayNew').options[0].selected=true;}

數了一下:2087個字符。


我們來了解一下微軟的説法:

http://support.microsoft.com/default.aspx?scid=kb;EN-US;q208427



Maximum URL length is 2,083 characters in Internet Explorer
Microsoft Internet Explorer has a maximum uniform resource locator (URL) length of 2,083 characters. Internet Explorer also has a maximum path length of 2,048 characters. This limit applies to both POST request and GET request URLs. 

If you are using the GET method, you are limited to a maximum of 2,048 characters, minus the number of characters in the actual path.

However, the POST method is not limited by the size of the URL for submitting name/value pairs. These pairs are transferred in the header and not in the URL. 

RFC 2616, "Hypertext Transfer Protocol -- HTTP/1.1," does not specify any requirement for URL length. 
已經明瞭. 我們最後的做法:

用一個JS function來給CustomerFunction瘦身,如下:

 <uc1:QLookUp ID="QLookUpVendorNew" runat="server" SelectOnly = "true"
                            CustomerFunction="if(clear!=1){objTextBoxText.value=arrayValue[1]+' '+arrayValue[2];SelectNewVendor(arrayValue);}else {document.getElementById('HiddenVendorIDNew').value='';document.getElementById('QTextBoxVendorTaxNew').value='';document.getElementById('QTextBoxVendorCurrencyNew').value='';document.getElementById('QTextBoxVendorSiteNew').value='';document.getElementById('DropDownListCurrencyNew').options[0].selected=true;document.getElementById('DropDownListTradeTermNew').options[0].selected=true;document.getElementById('DropDownListShipWayNew').options[0].selected=true;}"
                            alt="required::MSG500014::QButtonAdd" TextBoxCss="QTextBox" Width="160px" WindowTitle="Select Vendor" />

 

<script type="text/javascript">
        function SelectNewVendor(arrayValue)
        {
            document.getElementById('HiddenVendorIDNew').value=arrayValue[0];
            document.getElementById('QTextBoxVendorSiteNew').value=arrayValue[3];
            document.getElementById('QTextBoxVendorTaxNew').value=arrayValue[7];
            document.getElementById('QTextBoxVendorCurrencyNew').value=arrayValue[6];
            var dropCurrency=document.getElementById('DropDownListCurrencyNew');
            var dropTradeTerm=document.getElementById('DropDownListTradeTermNew');
            var dropShipway=document.getElementById('DropDownListShipWayNew');
             var neverSelect = true;
            //Currency DropDownList 
            if(arrayValue[6].length>0)
            {    
                neverSelect = true;           
                for(i=0;i<dropCurrency.options.length;i++)
                {
                    if(dropCurrency.options[i].text==arrayValue[6])
                    {
                        dropCurrency.options[i].selected=true;   
                        neverSelect = false;                        
                    }
                }               
                if(neverSelect == true) 
                {
                    dropCurrency.options[0].selected=true;       
                }   
            }
            else 
            {
                dropCurrency.options[0].selected=true;                
            }
            //Trade Term DropDownList
            if(trim(arrayValue[4]).length>0)
            {
                neverSelect = true;         
                for(i=0;i<dropTradeTerm.options.length;i++)
                {
                    if(dropTradeTerm.options[i].text==arrayValue[4])
                    {
                        dropTradeTerm.options[i].selected=true;   
                        neverSelect = false;                     
                    }
                }
                if(neverSelect == true) 
                {
                    dropTradeTerm.options[0].selected=true;       
                }    
            }
            else 
            {
                dropTradeTerm.options[0].selected=true;                
            }
            //Ship Way DropDownList
            if(arrayValue[5].length>0)
            {
                neverSelect = true;         
                for(i=0;i<dropShipway.options.length;i++)
                {
                    if(dropShipway.options[i].text==arrayValue[5])
                    {
                        dropShipway.options[i].selected=true;   
                        neverSelect = false;                     
                    }
                }
                if(neverSelect == true) 
                {
                    dropShipway.options[0].selected=true;       
                }
            }
            else
            {
                dropShipway.options[0].selected=true;                
            }
        }
        </script>

 

最後的URL:


http://hi4-ibmsv503/Pricing/Public/QLookUPSearchPage.aspx?SQL=+WOeqS2Mk/H6E9ICwIOpVbfgAjIPH2onkkRF7fO6kaqZMiq7gRww2LfgAjIPH2onb0G0aFlDKnaVkj5ZYTna9yDKAZJIz8t1GzKRU95Ah7BZ9czLL/8qv94OjoxTQh3qpAIlrIFYcgI/yWSRJXF+z0WkMLZGBidybjtuO86fXa/6zGD5BBrbqWLysS4RIoiQ/Oq2RKy/Ajodoh7HD8ZKV1oFf7uPqCGsYmBs6Ube9i5JGkg0e8sb/nN7x9b9SP8PqbyXWTXVbt98DyOiAYKN7awxVOfHJWy0OvMz9rA7KFv0p59zuOD8FNbB0jGbe/2Pu3D1GXeh6WxVE+6UVgrd8TRHpTYtNEN3KQhuZPWNhUI=&DataSource=9lDQbyO73rk=&ReturnClientID=QLookUpVendorNew&DataSourceType=EPS&WindowTitle=Select Vendor&CustomerFunction=if(clear!=1){objTextBoxText.value=arrayValue[1]!!!lionel!!!' '!!!lionel!!!arrayValue[2];SelectNewVendor(arrayValue);}else {document.getElementById('HiddenVendorIDNew').value='';document.getElementById('QTextBoxVendorTaxNew').value='';document.getElementById('QTextBoxVendorCurrencyNew').value='';document.getElementById('QTextBoxVendorSiteNew').value='';document.getElementById('DropDownListCurrencyNew').options[0].selected=true;document.getElementById('DropDownListTradeTermNew').options[0].selected=true;document.getElementById('DropDownListShipWayNew').options[0].selected=true;}

長度:1128個字符,OK了。