我有一个 ASPX (PictureGetter.aspx),它加载图像并以如下方式将它们写入响应:
private void WritePicture()
{
byte[] bytes = GetBytes(picPath);
Response.ContentType = "image/jpeg";
Response.Clear();
Response.BinaryWrite(bytes);
Response.End();
}
然后可以在这样的页面上使用它:
<img src="/path/to/PictureGetter.aspx?some_param=some_value" />
但是,在某些情况下,我将无法获取图像,因此我想将用户重定向到完全不同的页面:
if (some_condition)
{
Response.Redirect("/another/path/page.aspx");
}
else
{
WritePicture();
}
但是,重定向永远不会发生。我试过 Response.Redirect("/another/path/page.aspx", false) 和 Response.Redirect("/another/path/page.aspx", true) 但无济于事。有什么想法可以解决这个问题吗?