[英]Unable to see Redirect page name
我有一个带有LinkButton的页面,我的要求是单击“ DownLoad; Linkbutton该页面应重定向到另一个页面,并且应该下载我的文件,并且我的网页地址栏应显示该页面正在重定向的页面以及我的querystring值。 请建议我该怎么做,请帮助我。
这是我的代码
FirstPage.aspx
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("Default2.aspx?filename=Csharp/CSharp.txt");
}
下载.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();
}
我在Download.aspx页面事件的每个事件中都使用了此代码,但我没有。 注意:我确实有这个要求,我必须使用querystring,并且重定向的页面和querystring值应该在下载前显示在地址栏中。
使用附加标志指示应进行实际下载。 在此期间,您可以显示“请稍候”消息。 像这样:
<!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>
后台代码:
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.