简体   繁体   中英

How do I get a querystring into ashx file in c#

I have been checking the internet and there is one answer here at stackoverflow, but it is in vb.net, and I am using c#,

k, this is the deal, I have a binary image stored in a sql server db. I have that working great, to load it in and also to retieve it. In a gridview, I have a link for the detail of the master/detail page. I am using a simple html image tag in the html part here is the code:

I am using VS2010 and 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>

Here is the code behind:

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"];
      }
   }
}

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

  ...

My problem is the querystring variable, I have tried many many different ways to format the querystring coming from displayDetail02.aspx, but I can't seam to get the ' and " right to display the paramater, I keep getting '<%' which is the first part of query string.

I look at it in firebug in mozilla and the querystring is getting passed correctly, but it is not getting processed in the ashx file correctly.

I also tried it in the code behind etc, like here is some of the code I have tried.

<% --src='<%# "getLargeImage.ashx?Businessid=" + Eval("Businessid") %>' --%>

It is just one line of code ... oh, I know this works, because when I hardcode a parameter in the ashx (generic handler), I get the image back

Could someone please help me?

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

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

context.Request.Form["value"]

其中value是您传递的名称。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM