在IIS上从字节数组加载图像失败

时间:2018-08-11 09:11:33

标签: c# sql asp.net sql-server webforms

我在byte[]服务器中有一个图像(SQL)。当我将其转换为本地主机上的图像源时,它可以正常工作。但是,当它从IIS服务器IP服务器运行时,网页将无限期加载。

我的代码如下:

    void LoadCertificate()
    {
        try
        {
            DataTable dt = new DataTable();
            conn = new SqlConnection(ConnString);
            cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandText = "sp_getCertificateInfoForReport";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@EmpCode", TextBox1.Text);
            cmd.Parameters.AddWithValue("@CompanyID", 1);
            da = new SqlDataAdapter(cmd);
            conn.Open();
            da.Fill(dt);
            conn.Close();
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    byte[] bytes = (byte[])dt.Rows[i]["CImage"];
                    var divHtml = new System.Text.StringBuilder();
                    System.Web.UI.HtmlControls.HtmlGenericControl div = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
                    div.ID = "test";
                    Label lbl = new Label();
                    lbl.Text = dt.Rows[i]["Description"].ToString();
                    System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
                    string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);


                    img.ImageUrl = "data:image/jpeg;base64," + base64String;
                    img.Height = 400;
                    img.Width = 300;
                    img.AlternateText = "Test image";
                    div.Controls.Add(lbl);
                    div.Controls.Add(img);
                    Certificate.Controls.Add(div);             
                }
            }
        }
        catch (Exception ll)
        {

        }

    }

在我的aspx页面中:

<form id="form1" runat="server">
<div>

    <asp:TextBox ID="TextBox1" runat="server" Width="290px"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

</div>
<div ID="Certificate" runat="server">

</div>
</form>

该代码在localhost上运行良好,但是为什么在IIS上发布后却失败了?

0 个答案:

没有答案