ASP.NET - >有没有人处理图片的网址超过2500个字符? [英] ASP.NET -> Has anyone dealt with image Urls that are over 2500 characters?

查看:120
本文介绍了ASP.NET - >有没有人处理图片的网址超过2500个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的地方存储图像ASPX页面。这些图片的URL都是围绕2000个字符。

该URL的值是从什么地方读,我没有控制权。

我想知道是否有人已经处理这些类型的情况。

我有一个重建这个URL一个JavaScript程序。

所以我想知道,

a)如何处理那些时间长度更长的URL。 (我得到的OnInit的URL)。由于他们是更长的时间,我想用javascript函数,将修剪的URL长度。

二)一旦我得到重建的URL(这将是大约500字)我要分配给此回的图像,并让页面加载完成。为实现

由于提前,

更新0:我想知道如何HttpWebRequest的可用于在同一职位后的图像??

更新1:我已经更新了我原来的职位

更新2 的Javascript code。这code重建和提交文件。我很好的,因为它是我也可以只修改后的URL,然后在我的code-后面(的OnInit)将其分配到图像使用这个JavaScript。

 <脚本类型=文/ JavaScript的>
功能posturl(URL){
    变种qsBegin = url.indexOf(?);
    变种qsPattern =新正则表达式([&放大器;]([^ =] *)=(^&放大器;] *),IG);
    VAR匹配= qsPattern.exec(URL);
    VAR PARAMS =新的Array();    而(配合!= NULL){
        VAR matchID =匹配[1];
        如果(matchID.charAt(0)==&放大器;){
            matchID = matchID.substr(1);
        }        如果(PARAMS [匹配[1] = NULL&放大器;!&安培;!(PARAMS [匹配[1]的instanceof阵列)){
            VAR子阵列=新的Array();
            subArray.push(PARAMS [匹配[1]);
            subArray.push(UNESCAPE(匹配[2]));
            PARAMS [匹配[1] =子阵;
        }否则如果(PARAMS [匹配[1] = NULL&放大器;!&安培; PARAMS [匹配[1]的instanceof阵列){
            PARAMS [匹配[1]推(UNESCAPE(匹配[2]))。
        }其他{
            PARAMS [匹配[1] = UNESCAPE(匹配[2]);
        }
        匹配= qsPattern.exec(URL);
    }    VAR myForm会=使用document.createElement(表);
    myForm.setAttribute(目标,_blank);
    myForm.method =邮报;
    myForm.action = url.substring(0,qsBegin);
    对于(params中VAR K){
        VAR myInput;
        //检查具有相同名称的PARAMS。
        如果(PARAMS [K]的instanceof阵列){
            对于(VAR I = 0; I< PARAMS [K]。长度;我++){
                myInput = createFormInput(K,则params [k]的[I]);
                myForm.appendChild(myInput);
            }
        }其他{
            myInput = createFormInput(K,则params [K]);
            myForm.appendChild(myInput);
        }
    }    document.body.appendChild(myForm会);
    myForm.submit();
    document.body.removeChild(myForm会);
}


解决方案

这个问题是不是在什么样的protocal能够处理的长度,但在长度您的客户端可以处理。大多数的浏览器有大约2000个字符一个最大GET尺寸。如果您想了解更多,你需要一个其他浏览。不过这通常不是你的控制之下。


  

中的HTTP协议不会将任何先验限制上的长度
  URI。服务器必须能够处理任何资源的URI他们
  发球,并应能够在处理无限长度的URI他们
  提供可能产生这样的URI GET为基础的形式。服务器应该
  返回414(请求URI太长)状态,如果URI是长于
  服务器可以处理(见10.4.15)。


  
  

请注意:服务器应该是谨慎取决于URI长度
  上述255个字节,因为一些旧的客户或代理实现
  可能不正确地支持这些长度。


您可以尝试使用后的信息发送给服务器和图像回你的客户。

I have ASPX page where I store images. The URL for these images are around 2000 characters.

The value of this URL is read from somewhere and I don't have control.

I would like to know if anyone has handled these type of situation.

I have a javascript procedure that reconstructs this URL.

so I would like to know,

a) How to handle URLs that are longer in length. (I get the URL in OnInit). Since they are longer, I would like to use javascript function that will trim the URL length.

b) Once I get the reconstructed URL (which will be around 500 characters) I want to assign this back to the image and allow the page loading to complete. To achieve

Thanks in advance,

Update 0 : I would like to know how httpwebrequest can be used to post an image in the same post??

Update 1: I have updated my original post.

Update 2 Javascript code. This code reconstructions and the submits the document. I am fine with using this javascript as it is OR I can just the modified URL and then assign it to the image in my code-behind (OnInit).

<script type="text/javascript">
function posturl(url) {
    var qsBegin = url.indexOf("?");
    var qsPattern = new RegExp("[?&]([^=]*)=([^&]*)", "ig");
    var match = qsPattern.exec(url);
    var params = new Array();

    while (match != null) {
        var matchID = match[1];
        if ( matchID.charAt(0) == "&" ) {
            matchID = matchID.substr(1);
        }

        if ( params[match[1]] != null && !(params[match[1]] instanceof Array) ) {
            var subArray = new Array();
            subArray.push(params[match[1]]);
            subArray.push(unescape(match[2]));
            params[match[1]] = subArray;
        } else if ( params[match[1]] != null && params[match[1]] instanceof Array ) {
            params[match[1]].push(unescape(match[2]));
        } else {
            params[match[1]]=unescape(match[2]);
        }   
        match = qsPattern.exec(url);
    }

    var myForm = document.createElement("form");
    myForm.setAttribute("target", "_blank");
    myForm.method="post" ;
    myForm.action = url.substring(0,qsBegin) ;
    for (var k in params) {
        var myInput;
        // Check for params with the same name.
        if ( params[k] instanceof Array ) {
            for ( var i=0; i<params[k].length; i++ ) {
                myInput = createFormInput(k, params[k][i]);
                myForm.appendChild(myInput) ;
            }
        } else {
            myInput = createFormInput(k, params[k]);
            myForm.appendChild(myInput);
        }
    }

    document.body.appendChild(myForm) ;
    myForm.submit() ;
    document.body.removeChild(myForm) ;
}

解决方案

The problem is not in the length of what the protocal can handle, but in the length your client can handle. Most browser have a max get size about 2000 chars. If you want more you need an other browser. However that is normally not under your control.

The HTTP protocol does not place any a priori limit on the length of a URI. Servers MUST be able to handle the URI of any resource they serve, and SHOULD be able to handle URIs of unbounded length if they provide GET-based forms that could generate such URIs. A server SHOULD return 414 (Request-URI Too Long) status if a URI is longer than the server can handle (see section 10.4.15).

Note: Servers ought to be cautious about depending on URI lengths above 255 bytes, because some older client or proxy implementations might not properly support these lengths.

You can try to use a post to send the information to the server and return the image to you client.

这篇关于ASP.NET - &GT;有没有人处理图片的网址超过2500个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆