如何调用aspx页面并让它返回图像?

eri*_*cgr 6 c# asp.net image

******根据评论编辑发布到较新的代码示例*******

所以,要清楚,我有两个文件.第一个文件名为FinalImage.aspx,这是该页面的代码:

<html>
  <body>
    <img src="newpage.aspx" />
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

newpage.aspx具有以下代码,基于Jason在以下评论中的示例:

<%@ Page Language="C#" %>

<script runat="server" language="c#">

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.ContentType = "image/png";
        byte[] data = System.IO.File.ReadAllBytes("http://mystatus.skype.com/smallclassic/eric-greenberg");

        Response.OutputStream.Write(data, 0, data.Length);
        Response.OutputStream.Flush(); 
        Response.End();
    }

</script>
Run Code Online (Sandbox Code Playgroud)

如果我调用FinalImage.aspx,我会看到一个破碎的图像.

如果我直接调用newpage.aspx,我会得到"不支持URI格式错误"

不过,我认为它很接近.

此外,对于刚读这篇文章的人来说,需要这个解决方案来解决这样一个事实,即skype没有为其skype按钮提供https选项,告诉skype用户的状态.创建此代理页面将允许此工作,而不会在浏览器中导致"混合"安全警报.

eri*_*cgr 8

所以,这是最终的工作代码:感谢大家帮助跟踪这一点(可以这么说......)

<%@ Page Language="C#" %>

<script runat="server" language="c#">
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.ContentType = "image/png";

        System.Net.WebClient wc =  new System.Net.WebClient();

        byte[] data = wc.DownloadData("http://mystatus.skype.com/smallclassic/eric-greenberg");
        Response.OutputStream.Write(data, 0, data.Length);
        Response.OutputStream.Flush(); 
        Response.End();
    }
</script>
Run Code Online (Sandbox Code Playgroud)