ASP.NET -> Has anyone dealt with image Urls that are over 2500 characters?

246 Views Asked by At

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) ;
}
1

There are 1 best solutions below

3
On BEST ANSWER

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.