I have three values that are being generated dynamically in the code-behind of my web form. These three values will be shown to the user. While this may sound odd, I do NOT want the user to be able to copy and paste these values. Because of this, I would like to write out the values via an image that is build dynamically.
My question is, is there a way to dynamically create an image and write it out to the response? I would prefer not to create an image, save it to the server, and then pass a url back to the page. I would really like to write out the binary content along with the response. Is this possible? If so, can someone please explain/show how?
In the simplist form you can use
context.Response.BinaryWrite()to write a byte array to the response stream. Typically you would call this from a custom http handler that is mapped to a particular mime type – i.e. *.jpg or *.png etc..The following block of code shows one way to create a simple capcha image and return it as a byte array which can be consumed by
context.Response.BinaryWrite()Here is what your http handler might look like. Please note this is very basic and will get the job done, but does not include any image caching code, for client side or server side, which you will want to eventually add for performance.
Enjoy!