6

I am looking for a simple way to take a screenshot of an iFrame in my ASP page. I just couldn't achieve it with C# and I lack of knowledge of Javascript! Does anyone out there know the simple and best way to achieve this?

What I am trying to do is, I am building a website that students can log in to e-government website in my country and prove if they are continuing student with a single click so that they can get discount from our service.

Edit: The puzzle should be solved in local.

Cute Bear
  • 3,223
  • 13
  • 44
  • 69
  • Personally, I do not think a screenshot of an IFRAME is proof of much and would be significantly insecure as a concept of proving that a student is legitimate. I would advocate thinking up a different solution. – SpaceBison Feb 20 '12 at 14:27

3 Answers3

2

this piece of code worked for me. I hope it does the same to the others.

private void saveURLToImage(string url) 
    { 
        if (!string.IsNullOrEmpty(url)) 
        { 
            string content = ""; 


            System.Net.WebRequest webRequest = WebRequest.Create(url); 
            System.Net.WebResponse webResponse = webRequest.GetResponse(); 
            System.IO.StreamReader sr = new StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.GetEncoding("UTF-8"));

            content = sr.ReadToEnd(); 
            //save to file 
            byte[] b = Convert.FromBase64String(content); 
            System.IO.MemoryStream ms = new System.IO.MemoryStream(b); 
            System.Drawing.Image img = System.Drawing.Image.FromStream(ms); 
            img.Save(@"c:\pic.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); 


            img.Dispose(); 
            ms.Close(); 
        } 
    } 
Cute Bear
  • 3,223
  • 13
  • 44
  • 69
  • 1
    Does it even answer he question? The code isn't taking a screenshot. Also, it seems to be designed to download images and save them locally, even though there are framework methods for that. If you gave it a page URL, it wouldn't render it, so there's no image to save. – Edgar Mar 09 '16 at 13:10
0

Unless I'm misunderstanding you, this is impossible.

  • You cannot instruct the user's browser to take a screenshot (this would be a security risk … and has few uses cases anyway).
  • You cannot load the page you want a screenshot of yourself (with server side code) because you don't have the credentials needed to access it.
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
-2

server side Take a screenshot of a webpage with JavaScript?

javascript http://html2canvas.hertzen.com/

Community
  • 1
  • 1
Daniel B
  • 3,109
  • 2
  • 33
  • 42
  • This won't work [due to standard security restrictions](http://en.wikipedia.org/wiki/Same_origin_policy). – Quentin Feb 20 '12 at 14:33
  • if you on the 2nd link and then test console button you'll see that it takes a snapshot of the given link it's true that it needs the credentials for the given url to login. – Daniel B Feb 22 '12 at 14:44
  • To quote that page: "There are a lot of problems of loading external pages, even with a proxy, and as such many pages will not render at all." – Quentin Feb 22 '12 at 14:49
  • Also, since it requires using a proxy, it wouldn't be able to fetch the page that the OP wants a screenshot off … because that requires the user's credentials. – Quentin Feb 22 '12 at 14:50