Asp.net C#如果当前页面有查询字符串

时间:2017-11-17 14:34:42

标签: c# asp.net

我被困在这里。我有页面并通过request.query字符串打开它。因此称为products.aspx?Id=483

所以我的问题是我将如何从此页面重定向到仍需要传入变量的页面,在本例中为页面details.aspx?Id=56

没有这样做。我怎么会这样做的。任何帮助,我将不胜感激。

2 个答案:

答案 0 :(得分:0)

使用Request.QueryString上的HttpContext属性并使用Response.Redirect

例如:

string id = HttpContext.Current.Request.QueryString["id"];
if (!string.IsNullOrEmpty(id)) {
    Response.Redirect("/some-new-page.aspx");
}

答案 1 :(得分:0)

回答传递您需要的值,如下所示: + IdOrHiddenField1.value);

// Your new value is passed here to the next page after the plus sign
Response.Redirect("newPage.aspx?id=" + IdOrHiddenField1.value);

有两种方式可以做到这一点,

  1. Response.Redirect:Response对象的Redirect方法 提供了一种实现客户端重定向的方法。 Response.Redirect("http://www.yourwebpage.com");
  2. Server.Transfer:Server对象的Transfer方法执行 使用服务器重定向并避免HTTP请求。 Server.Transfer("/myPageWithString.aspx");
  3. Response.BufferOutput = true;
    string id = HttpContext.Current.Request.QueryString["id"];
    //check for empty string
    if (!string.IsNullOrEmpty(id)) {
        Response.Redirect("/myPageWithString.aspx?id=" + IdOrHiddenField1.value);
    }
    else if (Parse.Int.... == "some blah...")
    {
        Response.Redirect("/myPageWithString.aspx?id=" + IdOrHiddenField1.value);
    }