******根据评论将帖子编辑为较新的代码示例*******
所以,明确地说,我有两个文件。第一个文件称为 FinalImage.aspx,这是该页面的代码:
<html>
<body>
<img src="newpage.aspx" />
</body>
</html>
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>
如果我调用 FinalImage.aspx,我会看到损坏的图像。
如果我直接调用 newpage.aspx,我会收到“不支持 URI 格式错误”
不过我认为它很接近。
此外,对于刚刚阅读本文的任何人,需要此解决方案来解决 Skype 的 Skype 按钮没有 https 选项的事实,该选项可以告诉 Skype 用户的状态。创建此代理页面将允许此工作,而不会在浏览器中引起“混合”安全警报。
最佳答案
所以,这是最终的工作代码:感谢大家帮助您一点一点地追踪(可以这么说......)
<%@ 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>
关于c# - 如何调用 aspx 页面并让它返回图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3873685/