简体   繁体   English

无法看到重定向页面名称

[英]Unable to see Redirect page name

I have a page which has a LinkButton,my requirement is when i click on 'DownLoad; 我有一个带有LinkBut​​ton的页面,我的要求是单击“ DownLoad; Linkbutton the page should redirect to another page and there my file should be download and my web page address bar should display that which page it is redirecting also my querystring value. Linkbutton该页面应重定向到另一个页面,并且应该下载我的文件,并且我的网页地址栏应显示该页面正在重定向的页面以及我的querystring值。 please suggest me how would I do that please help me. 请建议我该怎么做,请帮助我。

here is my code 这是我的代码

FirstPage.aspx FirstPage.aspx

 protected void LinkButton1_Click(object sender, EventArgs e)
    {

        Response.Redirect("Default2.aspx?filename=Csharp/CSharp.txt");              
    } 


Download.aspx 下载.aspx

 protected void Page_Load(object sender, EventArgs e) <br/>

    {
        string filename = Request.QueryString["filename"];
        Response.ContentType = "text";
        Response.AppendHeader("Content-Disposition", "attachment; filename=CSharp.txt");
        Response.TransmitFile(Server.MapPath(filename));
        Response.End(); 
    }

I used this code in each and every event of Download.aspx page event but i couldn't. 我在Download.aspx页面事件的每个事件中都使用了此代码,但我没有。 note:I have this requirement exactly that i have to use querystring and also the redirected page and querystring value should show in the address bar before download. 注意:我确实有这个要求,我必须使用querystring,并且重定向的页面和querystring值应该在下载前显示在地址栏中。

Use additional flag to indicate that the the actual downloading should be made. 使用附加标志指示应进行实际下载。 In a meantime you can show a "Please wait" message. 在此期间,您可以显示“请稍候”消息。 Like this: 像这样:

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="refresh" content="3; url=<%=HttpUtility.HtmlAttributeEncode(Request.Url.OriginalString + &IsDownloading=true")%>">
  </head>

  <body>
    <h2>Your download will start shortly...</h2>
  </body>
</html>

Code-behind: 后台代码:

protected void Page_Load(object sender, EventArgs e)
{
    if(string.Compare((Request.QueryString["IsDownloading"] ?? string.Empty).Split(new char[] { ',' }).First(), "true", StringComparison.InvariantCultureIgnoreCase) == 0)
  {
    // Make a file transfer
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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