Showing posts with label WebBrowser. Show all posts
Showing posts with label WebBrowser. Show all posts

Thursday, December 27, 2012

Hosting images using Handler (ASHX)

In HTML, when we want to display images, we are using the following tag:

   <img src="images/myProfilePhoto.jpg"/>

That's very simple and has nothing much to complaint. But, you won't be able to trace who has requested the image file especially when the privacy issue comes into place... it becomes very nasty. In this case, we need to use ASP.NET Handler (ASHX) to host the images.

Advantage of hosting images through Handler:
  • You can hide the image file path. For example, your web app is located in D drive and all image files are stored in E drive (where you don't have to expose the image folder in IIS).
  • You may track down the visitor information that includes their IP address, browser, etc.
  • You may stored the images in a database and host it through the Handler - you don't need to create an image file physically and then write the phyicsal file name into "SRC" attribute. You just need to set the SRC attribute to your ASHX handler (refers to the sample code in the link below).
  • You may cache the images in the server.

In the HTML, you will have something like this:

  <img src="showPhoto.ashx?memberID=0001"/>

Where "showPhoto.ashx" is the Handler that you develop and "memberID" is the query parameter. Your handler should return the profile photo (in byte array) for member ID 0001.

For the code on how to implement the Handler or ASHX:

  http://stackoverflow.com/questions/994135/image-from-httphandler-wont-cache-in-browser
  http://stackoverflow.com/questions/1507572/streaming-databased-images-using-httphandler

For full explanations on the Handler:

   http://support.microsoft.com/kb/308001

Monday, March 26, 2012

WebBrowser control tweak

You may tweak the WebBrowser control in case it does not binding to the latest IE version (ie, different from the installed IE).

Below is the registry to be modify:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION]
"contoso.exe"=dword:00002328

The values for 'contoso.exe':

9999 (0x270F) - Internet Explorer 9. Webpages are displayed in IE9 Standards mode, regardless of the !DOCTYPE directive.
9000 (0x2328) - Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode.
8888 (0x22B8) -Webpages are displayed in IE8 Standards mode, regardless of the !DOCTYPE directive.
8000 (0x1F40) - Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode.
7000 (0x1B58) - Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode.

References:

For discussion, see here:
http://stackoverflow.com/questions/4612255/regarding-ie9-webbrowser-control

For the MSDN reference, see here:
http://msdn.microsoft.com/en-us/library/ee330730%28VS.85%29.aspx#browser_emulation

Monday, December 12, 2011

Embedding WebBrowser control in WinForm

This is not something new but very useful in embedding the WebBrowser control in WinForm:

http://notions.okuda.ca/2009/06/11/calling-javascript-in-a-webbrowser-control-from-c/

Pros:

  1. Multi-media mash up without much GDI calls - you can add nice images, sound and video in your WinForm without having to use GDI api to draw the nice effect.
  2. Able to utilize JQuery (or JavaScript) - this allows you to develop application that shares some of the library that you have developed between the WinForm and ASP.net.
  3. Able to do fancy menu without going through the WPF/Silverlight route - just use all the HTML and JavaScript that you have already learned.
  4. No more "can't built nice control" any more.

Cons:

  1. Over-used of the JavaScript and HTML in WinForm might create chaos. It increases the difficulties in debugging.
  2. You must posses HTML, JavaScript and C# skills. Of course, you must have the SQL skill as well.