通过将字符串查询传递给通用处理程序来避免Null值来自网页 - asp.net

时间:2015-09-21 16:34:01

标签: c# mysql asp.net

我使用Dim distinctDT As DataTable = dt.DefaultView.ToTable(True, "unit") Msgbox(distinctDT.Rows.Count) generic handler数据库获取图像我使用此代码对图像进行编码..

  

已修改:我使用MySql来获取“查询为会话”,但仍然显示IRequiresSessionStateenter image description here

null

                    string Key= Request.QueryString["Key"].ToString();
                Session["KeyImage"] = Key;

这是我的控制器图片

    public void ProcessRequest(HttpContext context)


    {
                    string Key= Request.QueryString["Key"].ToString();
        string ConnectionString = @"Server=MYSQL5011.Smarterasp.net;Database=db_9d6c52_ahmed;Uid=9d6c52_ahmed;Pwd=123123123;";
        MySqlConnection GetConnection = new MySqlConnection(ConnectionString);
        GetConnection.Open();
        string VoiceorScreenSearch = "Select * From User where User_Stat=@UserStat";
        MySqlCommand Comand = new MySqlCommand(VoiceorScreenSearch, GetConnection);
        Comand.Parameters.AddWithValue(@"UserStat",Key);
        MySqlDataAdapter DA = new MySqlDataAdapter(Comand);
            DataTable DT = new DataTable();
        DA.Fill(DT);
        byte[] Image = (byte[]) DT.Rows[0][1];
        context.Response.ContentType = "Image/jpg";
        context.Response.ContentType = "Image/jpeg";
        context.Response.ContentType = "Image/PNG";
        context.Response.BinaryWrite(Image);
        context.Response.Flush();



    }

这是我的<asp:Image ID="Image1" ImageUrl="HandlerImage.ashx" runat="server"></asp:Image> ,我可以在那里检索我的load page公众,因为我试图通过它来固有!但我没有用的东西!

Query

任何想法我将不胜感激..谢谢

1 个答案:

答案 0 :(得分:1)

实际上你忘记了控制器中的Key 它就像是

    <asp:Image OnLoad="Image1_Load2" ID="Image1"  Width="20%"  ImageUrl="HandlerImage.ashx?Key='<%Eval("Key")%> CssClass="fancybox" runat="server"></asp:Image>

或者您可以使用此

在页面加载时传递其参数
                            Image1.ImageUrl = "HandlerImage.ashx?Key=" + Request.QueryString["Key"].ToString();

应该工作:)