我正在使用通用处理程序
从MySql
数据库获取图像,我使用此代码对图像进行编码..
Edited : i'v used
IRequiresSessionState
to get Query As Session but i still getnull
value as shown
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/