1

I have app with two sites, one where design is done and other which returns Images.I was storing my values to generic types and then converted them to query string and just set Image src on desing page to return changes. Code was getting bad and I was struggling with diffrent data on every place(since I have few different objects,and few same).I finally gave up after long struggle with query strings because my data was always messed up becuase of 1000 converting to different types.

Well now I created classes for my objects and everything is perfect but now when I serialize my objects with LosFormatter and glue it up like:

 <img id="img" src="Image.aspx?image=/wEy8AgAAQAAAP////8BAAAAAAAAAAwCAAAAQkxpa2VNeVN0dWZmLCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49bnVsbAwDAAAAUVN5c3RlbS5EcmF3aW5nLCBWZXJzaW9uPTQuMC4wLjAsIEN1bHR1cmU9bmV1dHJh..." </img>

Nothing happens. Page "Image.aspx" doesn't even get called, nor I get any errors. I tried setting breakpoints to page_load and they never get hit.Everything worked fine with generic types and "normal" query string.Here is my LosFormatter Code:

public void RedrawImage()
{            
    System.Web.UI.LosFormatter formatter = new System.Web.UI.LosFormatter();
    StringWriter writer = new StringWriter();
    formatter.Serialize(writer,myObject);
    img.ImageUrl = "~/Image.aspx?image=" + Server.HtmlEncode(writer.ToString());
}

Has anyone had any similar issues?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
formatc
  • 4,261
  • 7
  • 43
  • 81
  • Is it possible that the concatenated ImageUrl is so large that it exceeds the maximum length of a URL (and therefore the data is invalid)? http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url – Roy Goode Feb 03 '12 at 18:29
  • Avarage url gets to about 1600 chars so I don't think so – formatc Feb 03 '12 at 18:30

1 Answers1

1

The problem might be unescaped characters in the query string. Try calling Server.UrlEncode instead of Server.HtmlEncode.

UPDATE: Based on the posted comments, the query string is evidently too long. You can increase the limit in Web.config:

<httpRuntime maxQueryStringLength="2048" />

See http://www.asp.net/whitepapers/aspnet4.

Michael Liu
  • 52,147
  • 13
  • 117
  • 150
  • I just realized and changed it to HttpUtilty.UrlEncode but still the page doesn't get called. – formatc Feb 03 '12 at 18:19
  • Does your page get called if you navigate directly to Image.aspx in your browser, without any query string? – Michael Liu Feb 03 '12 at 18:23
  • It gets called when I change img.ImageUrl = "~/Image.aspx"; – formatc Feb 03 '12 at 18:25
  • What about "~/Image.aspx?image=/wEy8AgAAQAAAP////"? – Michael Liu Feb 03 '12 at 18:27
  • When I decoded it properly now with HttpUtilty.UrlEncode it looks like "Image.aspx?image=%2fwEy8AgAAQAAAP%2f%2f%2f%2f8BAAAAAAAAAAwCAAAAQkxpa2VNeVN0dWZmLCBWZXJzaW9uPTEuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZ.." but still the same deal – formatc Feb 03 '12 at 18:32
  • I wonder if your query string is too long. See if the page is called if you truncate the query string after 20 or so characters. – Michael Liu Feb 03 '12 at 18:33
  • Page gets called when I truncate query after 20 chars, must be the length then, but I counted length and it is about 1600 chars. – formatc Feb 03 '12 at 18:36
  • @user1010609 You don't really want to exceed 255 characters in a URL just as a best practice. – Roy Goode Feb 03 '12 at 18:37
  • @ Roy Yeah, you are right, I will have to figure another way to pass it, but nothing comes to my mind.. – formatc Feb 03 '12 at 18:40
  • @user1010609 the object that you're serializing: can it be identified with an ID and stored in Session? – Roy Goode Feb 03 '12 at 18:43
  • @Roy Yes, I just started putting it to session.I Really don't know why I didn't try that first. Anyway thank you for feedback guyes! – formatc Feb 03 '12 at 18:46
  • @MichaelLiu Thanks for update,I will give that a try too and see what works betetr for me, hope my host doesn't limit legth. – formatc Feb 03 '12 at 18:48
  • hi @Michael for me deserialising the serialised data is showing error like invalid serialised data , The same code with same serialised data is working fine on another server.. how come it is debugged?? – clarifier Apr 01 '16 at 09:36
  • @clarifier: You should post a separate question. – Michael Liu Apr 01 '16 at 13:38