Stop asp.net image management automatically UrlEncoding ImageUrl parameter

By default, asp.net image management tries to be useful and automatically encodes everything that is set in the ImageUrl property, so:

imgSomething.ImageUrl = "Generator.aspx?x=1&y=2&z=3"; 

becomes

 "Generator.aspx?x=1&y=2&z=3" 

The problem is that I want to pass the Base64 encoded parameters that I need manually to Server.UrlEncode, because everyone can contain a charater, which otherwise will cause problems.

So basically, my question is: How to stop automatic image control using UrlEncoding, what did I set in the ImageUrl parameter?

+4
source share
2 answers

We faced the same problem. Our solution was to pack all the parameters into one URLEncoded and Base64-encoded parameter and split it on the other side. We observe a similar approach in WebResource.axd and ScriptResource.axd.

Quick and dirty way (using simple helper methods for Base64 encoding / decoding):

 string parameters = args.Join('|'); imgSomething.ImageUrl = "Generator.aspx?d=" + Server.UrlEncode(Base64Encode(parameters)); 

in Generator.aspx:

 string data = Base64Decode(Server.UrlDecode(Request.QueryString["d"].ToString().Trim())); string[] parameters = data.Split('|'); 

If you want to use parameter strings in the querystring style (i.e. x = 1 & y = 2 & z = 3), there is a bunch of example code that will let you navigate between the string and the name ValueCollection.

+2
source

I think you should use server control. not controlled by asp.

 <img ID="Image2" src="" alt="" runat="server" /> Me.Image2.Src = "&&&" 

it works.

+6
source

All Articles