English 中文(简体)
从服务器档案系统中获取图像,在伙伴关系中具有活力。 NET,通过jquery
原标题:Loading an image from the server s file system dynamically in ASP.NET, via jquery

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
问题回答

如同连接点一样,它取消其违约行动。 你可以尝试改变你的职能。

$(".thumbnail").click(function (e) {
    e.preventDefault();

    var image = $(this).attr("href");
    $( #photoLarge ).html( <img src="  + image +  "/> ).hide().fadeIn( slow );
});




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签