Groups > Asp .Net > HttpHandlers and HttpModules > Re: HttpHandler, to show images




HttpHandler, to show images

HttpHandler, to show images
Mon, 10 Mar 2008 12:52:44 +000
I have created a HttpHandler to show images.It takes and encrypted parameter
from the QueryString and decodes it and get the path to the image and the size
the image is to be displayed in.

This works great, i use it like so:

<img id="currentImage" src='/ShowImage.ashx?<%
Response.Write(Context.Server.UrlEncode(Utils.Encrypt("/test.jpg&200&am
p;0"))); %>'/>

But when i try to change the displayed image by javascript, it fails. I have
debugged and found that the encrypted string the HttpHandler gets from
javascript cantains and '+', which is UrlDecoded to %2b, when not using
javascript. I have looked at the html source, here the url also i urldescoded to
%2b. I guess javascript does something to the url.

Does anybody have some input??

<ahref="javascript:changeImage('/ShowImage.ashx?<%
Response.Write(HttpUtility.UrlEncode(Utils.Encrypt("/test.jpg&200&0
"))); %>');">Change</a>

<scripttype="text/javascript">function
changeImage(path){document.getElementById('currentImage').src = path;

}

</javascript>



 /Anders
Post Reply
Re: HttpHandler, to show images
Tue, 11 Mar 2008 05:13:49 +000
Yup, you can't changed it using only javascript. Handler work on the server
therefore when you change it using only javascript. Handler won't work.

Hope it helps,

Near
Post Reply
Re: HttpHandler, to show images
Tue, 11 Mar 2008 07:45:34 +000
Figued out what was wrong. Javascript did change the url, can't say why or how.
But it did. I changed my javascript function to:

<script type="text/javascript">
    function changeImage(path){
        path = escape(path);
        path = path.replace(/\+/g, '%2b');
        path = path.replace(/\=/g, '%3d');    
        document.getElementById('currentImage').src = '/ShowImage.ashx?'+path;
    }
</script>

 

And now it works fine.

 

/Anders
Post Reply
about | contact