【发布时间】:2009-04-30 16:12:54
【问题描述】:
我正在调用一个 Web 服务,它以字节数组的集合的形式返回未知数量的图像。 (我无法改变)
我需要在单个 aspx 网页上显示每个图像。
我目前正在使用 Microsoft.Web.GeneratedImage 控件; http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=16449 显示图像。
我遇到的问题是,由于控件调用单独的代码文件来加载图像内容,我使用会话状态来存储字节数组,我对此并不太满意。
这是我的测试项目中的一些代码;
Private Sub btnGetChart_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGetChart.Click
Dim reportHub As New HubWrapper
Dim repCharts() As ReportHub.Chart = reportHub.ReportHubChart(Me.ddlReports.SelectedValue, ViewState("params"))
For Each chart As ReportHub.Chart In repCharts
Dim sessionKey As String = "img" & System.Guid.NewGuid().ToString
Dim imgParam As New Microsoft.Web.ImageParameter()
imgParam.Name = "sessionVar"
imgParam.Value = sessionKey
Session(sessionKey) = chart.ChartData
Dim img As New Microsoft.Web.GeneratedImage
img.ImageHandlerUrl = "~/chartImageHandler.ashx"
img.Parameters.Add(imgParam)
phChart.Controls.Add(img)
Next
End Sub
<%@ WebHandler Language="VB" Class="chartImageHandler" %>
Imports System
Imports System.Collections.Specialized
Imports System.Drawing
Imports System.Web
Imports Microsoft.Web
Public Class chartImageHandler
Inherits ImageHandler
Implements IRequiresSessionState
Public Sub New()
MyBase.New()
'Set caching settings and add image transformations here
'EnableServerCache = True
End Sub
Public Overrides Function GenerateImage(ByVal parameters As NameValueCollection) As ImageInfo
Dim byteArry As Byte() = CType(HttpContext.Current.Session(parameters("sessionVar")), Byte())
HttpContext.Current.Session.Remove(parameters("sessionVar"))
Return New ImageInfo(byteArry)
End Function
End Class
实现这一目标最优雅的方式是什么?
欢迎任何意见!!!
编辑:附加信息;
- 来自网络服务的图像是 来自 SQL 报告服务。
- 图像通常是 一直在变化(没有真正的 缓存要求)。
- 图像将是用户特定的。
- Web 服务每页只调用一次。
- 我实际上正在处理来自 生成后的会话状态 图像使用它,因为图像不会 需要再次查看 同时。
【问题讨论】:
标签: asp.net vb.net image bytearray codeplex