Take the 2-minute tour ×

I've read tons of other questions and googled the issue, but I can only figure out how to do it if I'm using winforms. I'm currently writing a library, and one of the functions of the library is to handle logging. One of the features I'm implementing for it is to automatically take a screenshot of the page before writing the issue to the log. The issue with this is that I don't know which monitor to take a screenshot of, so if the user moves the browser to a different monitor, I still take a shot of the Primary one.

public static Bitmap ScreenShot(string saveLocation, string fileName)
    Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
    Graphics.FromImage(bitmap).CopyFromScreen(0, 0, 0, 0, bitmap.Size);
    string savePath = Path.Combine(Path.GetDirectoryName(saveLocation), "ScreenShots");
    if (!Directory.Exists(savePath))
    bitmap.Save(Path.Combine(savePath, fileName), ImageFormat.Png);
    return bitmap;

I've tried Screen.FromControl(), but since it's not a winforms application, I don't have any System.Windows.Forms.Controls for it to find.

Does ASP.NET have any equivalent? Or something I can explicitly cast to a winform control?

share|improve this question
It is fundamentally impossible to take a screenshot in ASP.Net. –  SLaks Jul 18 '11 at 19:55
Your Screenshot() methods runs server-side - how can it possibly take a screenshot of the client? –  n8wrl Jul 18 '11 at 19:55
Won't this only work at all if the browser is running on the same computer as the ASP server? –  antlersoft Jul 18 '11 at 19:56
Snatch the code you have and convert to javascript :). –  JonH Jul 18 '11 at 19:57
And even then, how would ASP.NET know? tricks with localhost? –  n8wrl Jul 18 '11 at 19:58

8 Answers 8

up vote 4 down vote accepted

Surely any code you're running here will be running on the server so will have no idea where its being displayed

In theory you could use JS to capture the DOM and then send it back to the service via an Ajax call - that's the closest you'll get I would think

share|improve this answer
The DOM was the next thing I was going to try if I found out this wasn't going to work (which I guess it really wouldn't). Thanks for the answer! –  Sivvy Jul 18 '11 at 20:04

This just won't work. Your c# code is running on the web server, not on the user's web browser and not on their computer. The only monitors that code will have access to are the monitor attached to your web server.

This probably appears to work on your development platform, but only because there your web server and your client machine are the same machine.

The best you can hope for is to include a flash or silverlight object on the page that can take the capture, and even that probably won't work.

share|improve this answer
Yea, I wasn't entirely sure it would work, but I had hoped because of all the easy to find tutorials talking about taking screen shots of ASPX pages, that it would somehow be possible. –  Sivvy Jul 18 '11 at 20:03
In Silverlight and Flash both, you can capture the screen. However, it will only capture the Silverlight/Flash client area of the browser. In other words, only the part of the browser where the Silverlight component is running will be captured –  icemanind Jul 18 '11 at 20:09

You're trying to take a screenshot of the client's screen from an ASP.NET application? That isn't possible. You may be able to log the entire request including the HTML then re-render it somewhere else, but you can't have that kind of interaction with the client from a server-side application framework.

share|improve this answer


ASP.NET runs on the server, so writing server code to screen capture the browser is meaningless. You may have better luck using client-side code (javascript) to take a screenshot.

This thread uses an ActiveX solution: Take a screenshot of a webpage with javascript?

share|improve this answer

ASP.Net WebForms do not work as you might be thinking they do. The short answer is no, you cannot do this in ASP.Net. There is no equivalent.

WinForms are displayed by interacting with the Windows operating system and are shown on the same computer's desktop. WebForms are displayed by generating HTML and sending the HTML to another computer's browser. Your ASP.Net code is not running on the other computer's browser. If your code is attempting to take a screen shot, then at-best, you will get the server's (or your computer's) display.

You can run code on the browser using JavaScript - but you still shouldn't be taking screen shots (and I don't think JavaScript will let you - at least not automatically). For one, you will be including other information from their screen which may not be related.

When ASP.Net encounters a problem, it will log the details in the Windows log on the server and also (with less detail) in the IIS log files. Consider emailing yourself an alert when an error is encountered and looking in the logs to see what went wrong.

share|improve this answer

I would steal the algorithm currently used by google+. I definitely do not have the exact algorithm, or even one that is close to the actual thing, but I think this is what it's doing:

  • user clicks on 'log/report error'
  • server renders the current page using the position of the scroll bar and the size of the window (accessible through JS).
  • server renders a div covering the entire window and places the image inside of it. This div has the highest z-index.
  • when the user clicks on the div, a new div is generated that allows the user to "highlight" selected areas. The user is then allowed to attach a comment to this selected area.

It's genius in execution.

share|improve this answer

The only possiblity I can think of is something client-side that asks the browser to take a screenshot and then upload it. FogBugz does something like this with its new-case tool but that's an add-in your users would have to download and install.

share|improve this answer

I did this for a bug tracking app a long time ago using an ActiveX control written in --gasp-- Visual Basic. Something like that (other than the cool Google+ trick mentioned) is about your only choice.

share|improve this answer

Your Answer


