如何在c#中将查询字符串输入ashx文件

Mic*_*ury 7 c# asp.net

我一直在检查互联网,stackoverflow有一个答案,但它是在vb.net,我使用的是c#,

k,这是交易,我有一个存储在sql server db中的二进制映像.我有这个工作很好,加载它,也是为了解决它.在gridview中,我有一个主/详细页面详细信息的链接.我在html部分使用一个简单的html图像标签,这里是代码:

我正在使用VS2010和C#

(displayDetail02.aspx)

<body>
<form id="form1" runat="server">
<div>
  <img id="Img1" width="500" 
               runat="server" 
               src="~/getLargeImage.ashx?Businessid=<%Eval(businessid)%>"
               alt="Business Image" 
               style="border: 1px inset"/>
</div>
</form>
</body>
Run Code Online (Sandbox Code Playgroud)

这是后面的代码:

public partial class displayDetail02 : System.Web.UI.Page
{
   public string businessid = string.Empty;

   protected void Page_Load(object sender, EventArgs e)
   {
      if (!Page.IsPostBack)
      {
        businessid = Request.QueryString["businessid"];
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

(getLargeImage.ashx)

 public partial class getLargeImage : IHttpHandler {


 public void ProcessRequest(HttpContext context)
 {
    HttpContext _context = HttpContext.Current;
    context.Response.ContentType = "image/jpg";
    string businessid = Convert.ToString(context.Request.QueryString["businessid"]);    

  ...
Run Code Online (Sandbox Code Playgroud)

我的问题是查询字符串变量,我已经尝试了许多不同的方法来格式化来自displayDetail02.aspx的查询字符串,但我无法找到'和'右边显示参数,我不断得到'<%'是查询字符串的第一部分.

我在mozilla中的firebug中查看它,并且查询字符串正确传递,但它没有在ashx文件中正确处理.

我也在后面的代码中试过它,就像这里是我尝试过的一些代码.

<% --src='<%# "getLargeImage.ashx?Businessid=" + Eval("Businessid") %>' --%>
Run Code Online (Sandbox Code Playgroud)

它只是一行代码......哦,我知道这很有用,因为当我在ashx(通用处理程序)中对参数进行硬编码时,我得到了图像

有人可以帮帮我吗?

Red*_*Red 10

我这样使用ashx,尝试使用它:

context.Request.Params["string"]
Run Code Online (Sandbox Code Playgroud)


Mag*_*nus 4

protected void Page_Load(object sender, EventArgs e)
   {
      if (!Page.IsPostBack)
      {
        Img1.Src = "~/getLargeImage.ashx?Businessid=" + Request.QueryString["businessid"];
      }
   }
Run Code Online (Sandbox Code Playgroud)