asp.net web页面显示服务器绝对路径下图片

asp.net web页面显示服务器绝对路径下图片

注意:服务器端存储图片的文件夹要开发权限给asp.net(NetWorkService)用户权限,

我一般是在文件夹(假设是DownLoadFile文件夹)的“安全”中添加everyone用户授予全部权限。

 

webpage中代码

 Me.img.Attributes("src") = "../ShowAbsolutePathPic.aspx?URL=E:\pic\test.jpg"

 

ShowAbsolutePathPic.aspx的Page_Load事件代码:

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ' "根据照片路径,将照片转为二进制数组"    
        Dim strUrl As String = Request.QueryString("URL")
        Dim aFile As FileStream
        aFile = New FileStream(strUrl, FileMode.OpenOrCreate, FileAccess.ReadWrite)
        Dim brMyfile As BinaryReader
        brMyfile = New BinaryReader(aFile)
        brMyfile.BaseStream.Seek(0, SeekOrigin.Begin)
        Dim photo As Byte()
        photo = brMyfile.ReadBytes(Convert.ToInt32(aFile.Length.ToString()))
        brMyfile.Close()
        Response.BinaryWrite(photo)

    End Sub


 

你可能感兴趣的:(图片,asp.net,显示服务器绝对路径)