UPDATE: This is now a dead question. While debugging further I realized the server (which I need to test this part of my code on, due to file permissions and such) was not getting my updates from VS2010, even though I published them to it. Frustrating. Anyway, all this works fine. Perhaps it could be used by someone else trying to figure out how to do a similar thing? Thanks everyone for your help.
几天后,我一直 driving。
我有一个简单的图像th子清单,在被点击时,应该通过一些 j子在另一个小区展示全方位的形象。
我从数据库中获取th形图像数据和全方位图像档案。 相应的全方位图像存放在与IIS公司相同的服务器上。
We do not want to display the filepath in the rendered HTML, so what we do is encrypt the filepath and send that as a parameter to a generic handler, which decrypts it, loads the file from the server, and outputs it as a byte array stream.
但是,在试图做争.时,问题就会出现。 它不展示四肢中的图像,而是打开了一个新的浏览器表,显示手稿的形象,就像白喉残疾一样。 我需要的是图象,以图象显示,如果我们使用URL或某种图像,就会发生这样的情况。
我的相关守则如下:
观点:
<ul class="thumbnails">
@For Each photo In Model.Photos
Dim p As MyProject.Models.FolderImage = photo
Dim FullSizeLink As String = "/Handlers/GetImage.ashx?file=" & p.DocPath
@:<li><a href="@FullSizeLink" class="thumbnail"><img src="@p.Thumbnail.ToString" /></a></li>
Next
</ul>
<div id="photoLarge"></div>
j)
$(".thumbnail").click(function () {
var image = $(this).attr("href");
$( #photoLarge ).hide();
$( #photoLarge ).fadeIn( slow );
$( #photoLarge ).html( <img src=" + image + "/> );
return false;
});
My Handler:
Public Class GetImage
Implements System.Web.IHttpHandler
Implements System.Web.SessionState.IRequiresSessionState
Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim Common = New Common
Dim FilePath As String
Dim FileInfo As System.IO.FileInfo
Dim FileStream As System.IO.FileStream
Dim FileLengthInBytes As Long
Dim QueryString As String
Dim EncryptionKey as String = "df235s!2" that s not my real key ;-)
Try
QueryString = context.Request.QueryString("file")
FilePath = Common.DecryptString(QueryString.Replace(" ", "+"), EncryptionKey).Replace("+", " ")
FileInfo = New System.IO.FileInfo(FilePath)
FileStream = FileInfo.OpenRead()
FileLengthInBytes = FileStream.Length
If (FileLengthInBytes > 0) Then
Dim FileData(FileLengthInBytes - 1) As Byte
FileStream.Read(FileData, 0, FileLengthInBytes)
FileStream.Close()
context.Response.Clear()
context.Response.ContentType = "image/jpeg"
context.Response.OutputStream.Write(FileData, 0, FileData.Length)
context.Response.End()
End If
Catch ex As IOException
ReturnImageNotFound(context)
End Try
End Sub
ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
etc
End Class