Having problems with loading data using WebRequest.

K

Ken Varn

I have a WinForm UserControl that I am hosting in an ASP.NET web page. In
the UserControl, I am trying to load an image into a GDI Image object using
HttpRequest.

The problem that I am having is after instantiating the HttpRequest object,
I call the GetResponse method of the request. Right after this call, all
code that follows is skipped. No exception is thrown. I can't understand
what is happening here. Can someone help?

Example:

void LoadImage()
{
UriBuilder ImageUri = new UriBuilder(http://MySite/MyImage.jpg);
WebRequest Request;
WebResponse Response;
Bitmap Img;

try
{
Request = new WebRequest(ImageUri.Uri);
Response = Request.GetResponse();

// This is line is skipped and we immediately exit the function
Img = new Bitmap(Response.GetResponseStream());
}
catch(Exception Ex)
{
String Msg = Ex.Message; // I never get an exception.
Breakpoint is never hit.
}
}



--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
 
B

Bryan

Hi Ken,
I have done some extensive development with IE hosted controls. I have found
that the .net framework is very picky about security when it comes to this,
sometimes no security exception is thrown. Could it be you are trying to
access the file system on the PC? Another thing to do is put the
InitializeComponent in a try-catch, this will catch all errors.

Bryan
 
K

Ken Varn

It seemed to be related to the location of the call. I had it in a public
property and then moved it into its own function. After doing this, I was
able to intercept the exception in the debugger. Strange.

Turns out it was a security exception.

I am just starting to get my feet wet in this area with web hosted winform
controls. If you know of any good reference materials, please let me know
where I can find them.

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
Bryan said:
Hi Ken,
I have done some extensive development with IE hosted controls. I have found
that the .net framework is very picky about security when it comes to this,
sometimes no security exception is thrown. Could it be you are trying to
access the file system on the PC? Another thing to do is put the
InitializeComponent in a try-catch, this will catch all errors.

Bryan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top