0

我从数据库中获取字节并将它们转换为图像并将其发布到asp:image;尽管页面在本地正常工作,但当页面托管在服务器中时它不起作用。为什么会这样?这也不是 JS 错误,很可能是异常。

错误:gdi+ 中发生一般错误

ASP VB.NET 代码

 ds = objPicturess.GetALLPicturesByCategoryIdnCusId(dplCustomer.SelectedValue, dplCategory.SelectedValue, dtpFromDate.Date, dtpToDate.Date)
                If ds.Tables(0).Rows.Count <> 0 Then
                    For i = 0 To ds.Tables(0).Rows.Count - 1
                        Dim imageContent As Byte() = DirectCast((ds.Tables(0).Rows(i)("Picture")), Byte())
                        byteArrayToImage(imageContent, ds.Tables(0).Rows(i)("PictureTitle"), ds.Tables(0).Rows(i)("Remarks"))
                        'Response.BinaryWrite(imageContent)
                    Next
                    DataList1.DataSource = dt
                    DataList1.DataBind()
                Else
                    DataList1.DataSource = Nothing
                    DataList1.DataBind()
                End If

Public Sub byteArrayToImage(ByVal byteArrayIn As Byte(), ByVal strFile_Name As String, ByVal strRemarks As String)
        Try

            Dim newImage As System.Drawing.Image
            Dim strFileName2 As String
            strPictureTitle = ""
            strPictureTitle = strFile_Name
            strFileName = ""
            strFileName = "~/PictureGallery/" & strFile_Name & ".jpg"
            strFileName2 = Server.MapPath("~/PictureGallery/" & strFile_Name & ".jpg")
            Dim f As New IO.FileInfo(strFileName)
            If Not f.Exists Then
                Using stream As New MemoryStream(byteArrayIn)
                    newImage = System.Drawing.Image.FromStream(stream)
                    newImage.Save(strFileName2)
                End Using
            End If
            dr = dt.NewRow()
            dr("PictureTitle") = strPictureTitle
            dr("Picture") = strFileName
            dr("Remarks") = strRemarks
            dt.Rows.Add(dr)

        Catch ex As Exception
            ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "message", "alert('" + ex.Message + "');", True)
        End Try
    End Sub

ASPx 代码

 <ItemTemplate>
      <asp:Label ID="Label1" runat="server" Font-Bold="True" Text ='<%# Eval("PictureTitle")%>'

         Font-Size="10pt" ForeColor="#336699" Width="100%" />
      <br /> 
     <asp:ImageMap  BorderWidth="1px" BorderColor="Black" runat="server" Height = "175px" ID="imageZoom" Width = "172px" ImageUrl= '<%# Eval("Picture")%>'   StyleFolder="styles/simple"  BigImageUrl='<%# Eval("Picture")%>'/>
     <br />
     <asp:Label ID="lblRemarks" runat="server" Font-Bold="True" Text ='<%# Eval("Remarks")%>' Font-Size="10pt" ForeColor="#336699" Width="100%" /> 

   </ItemTemplate>
4

2 回答 2

1

您可以直接通过 IIS 访问文件夹安全/权限:

  1. 打开inetmgr(开始>运行> inetmgr)
  2. 展开您的站点并右键单击要写入图像的文件夹
  3. 点击“编辑权限”
  4. 转到安全选项卡
  5. 将适当的帐户添加到授权用户列表和/或确保该帐户具有写入权限。
  6. 应用更改
于 2013-10-07T05:51:46.677 回答
0

Give permission to your folder from IIS

于 2013-10-07T05:45:16.240 回答