URL也有长度限制?

微软说:"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。
20077121795s.jpg
点出来的页面如下:
2007712171622s.jpg
因为当点选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 = "None.gif
if (clear != 1 )
None.gif{
None.gif    objTextBoxText.value
= arrayValue[ 1 ];
None.gif    document.getElementById('HiddenVendorIDNew').value
= arrayValue[ 0 ];
None.gif    document.getElementById('QTextBoxVendorNameNew').value
= arrayValue[ 2 ];
None.gif    document.getElementById('QTextBoxVendorSiteNew').value
= arrayValue[ 3 ];
None.gif    
if (arrayValue[ 6 ].length > 0 )
None.gif    {
None.gif        
var  DropDownListCurrencyNew = document.getElementById('DropDownListCurrencyNew');
None.gif        
for (i = 0 ;i < DropDownListCurrencyNew.options.length;i ++ )
None.gif        {
None.gif            
if (DropDownListCurrencyNew.options[i].text == arrayValue[ 6 ])
None.gif            {
None.gif                DropDownListCurrencyNew.options[i].selected
= true ;
None.gif                
None.gif            }
None.gif        }
None.gif    }
if (arrayValue[ 4 ].length > 0 )
None.gif    {
None.gif        document.getElementById('DropDownListTradeTermNew').value
= arrayValue[ 4 ];
None.gif        
None.gif    }
else  
None.gif    {
None.gif        document.getElementById('DropDownListTradeTermNew').options[
0 ].selected = true ;
None.gif        
None.gif    }
if (arrayValue[ 5 ].length > 0 )
None.gif    {
None.gif        document.getElementById('DropDownListShipWayNew').value
= arrayValue[ 5 ];
None.gif        
None.gif    }
else  
None.gif    {
None.gif        document.getElementById('DropDownListShipWayNew').options[
0 ].selected = true ;
None.gif        
None.gif    }
None.gif}
else  
None.gif{
None.gif    document.getElementById('HiddenVendorIDNew').value
= '';
None.gif    document.getElementById('QTextBoxVendorNameNew').value
= '';
None.gif    document.getElementById('QTextBoxVendorSiteNew').value
= '';
None.gif    document.getElementById('DropDownListCurrencyNew').options[
0 ].selected = true ;
None.gif    document.getElementById('DropDownListTradeTermNew').options[
0 ].selected = true ;
None.gif    document.getElementById('DropDownListShipWayNew').options[
0 ].selected = true ;
None.gif    
None.gif}"

我们来看看点击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

None.gif None.gifMaximum URL length is 2,083 characters in Internet Explorer
None.gifMicrosoft 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. 
None.gif
None.gifIf 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.
None.gif
None.gifHowever, 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. 
None.gif
None.gifRFC 2616, "Hypertext Transfer Protocol -- HTTP/1.1," does not specify any requirement for URL length. 

已经明了. 我们最后的做法:

用一个JS function来给CustomerFunction瘦身,如下:

None.gif   < uc1:QLookUp  ID ="QLookUpVendorNew"  runat ="server"  SelectOnly  = "true"
None.gif                            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;}"
None.gif                            alt
="required::MSG500014::QButtonAdd"  TextBoxCss ="QTextBox"  Width ="160px"  WindowTitle ="Select Vendor"   />


 

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值