WebClient not returning a valid response

by joey.westcott 12. September 2009 19:44


A while back I was trying to consume some XML from a third party site and I found myself getting stuck on an error.  The site would not give me a valid response and would throw up a 403 error.  After digging around I found that I left off the user-agent info in the request header.  So the moral to this story is: Don't forget your user-agent!

Code Sample after the break.
More...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Development | .Net

ImageButton's ImageUrl not resolving correctly

by joey.westcott 16. August 2008 18:29

I was working with an image button the other day and for the life of me I couldn't get rid of a runtime error when it went to load the control.  I had a dynamic URL that was something similar to this:

   1:  ImageUrl='../ImageHandler.ashx?File=<%#Eval("Path") %>&MaxSize=<%=PhotoMaxSize %>&ApplyWaterMark=<%=ApplyWatermark %>'

 

The problem with this is that when the .Net Framework goes to parse this property it first see the "../*" and then goes down a routine to parse the path out, BUT forgets about the fact that I might have something in the URL that needs to be resolved.  It did take me quite a while to figure out what was going on and why the "resolved " path was the same as what was between the quotes. 

My solution was to change it up just a little bit, here is what I ended up with:

   1:  ImageUrl='<%# string.Format("../ImageHandler.ashx?File={0}&MaxSize={1}&ApplyWaterMark={2}", Eval("Path"), PhotoMaxSize, ApplyWatermark) %>' 

The result is the same but I just used a little help from the oh so nice string.Format method. Now because the URL didn't start with "../" or even "~/" it looked and noticed that it needed to resolve what is in the <%#...%>.  On a side note this also applies to the other properties on the control and i would assume that other controls are handled the same way.

 

I don't know maybe I should have known this before now.

Currently rated 5.0 by 4 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Development | .Net

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen