c# - 通过从网页将字符串查询传递到通用处理程序来避免空值 - asp.net

标签 c# mysql asp.net

我正在使用通用处理程序MySql数据库获取图像,我使用此代码对图像进行编码..

Edited : i'v used IRequiresSessionState to get Query As Session but i still get null value as shown enter image description here

                    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();



    }

这是我的 Controller 图像

<asp:Image ID="Image1"  ImageUrl="HandlerImage.ashx" runat="server"></asp:Image>

这是我的加载页面,我可以在其中检索我的查询它是公开的,因为我试图从中获取固有信息!但我没有得到任何有用的东西!

   public void Page_Load(object sender, EventArgs e)
    {
        String Key= Request.QueryString["Key"].ToString();
        TestConnection TrytoSearchforData = new TestConnection();
        TrytoSearchforData.TestUser(Key);

    }

任何想法我都会感激不尽..谢谢

最佳答案

实际上你忘记了 Controller 中的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();

应该有效:)

关于c# - 通过从网页将字符串查询传递到通用处理程序来避免空值 - asp.net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32700267/

相关文章:

c# - 无法连接到服务器(WAMP、phpmyadmin),将VS连接到数据库?

mysql - Apache和MySQL windows服务的使用

php - 显示来自sql查询的数组信息

javascript - ASP.NET 中通用容器的设计模式

c# - ASP.NET MVC4 实体验证错误 : User name already taken

c# - 使用子字符串获取特定间隔

c# - .NET DB2 OLEDB 先决条件

c# - 如何使用 Windows Search API 将文件夹添加到 Windows 索引列表中

php - 函数返回 boolean 值而不是适当的值

asp.net - ScriptManagers 的 ScriptMode 中的 Debug 和 Release 有什么区别?