I have a Master page with an iFrame.
Tickets.aspx has this Master. General.aspx is without any Master and loads inside the iFrame.
Both the pages have buttons to download files.
When downloading file from General.aspx, it shows this error.
Unable to evaluate expression because the code is optimized or a
native frame is on top of the call stack.
General.aspx.cs:
protected void View (object sender, CommandEventArgs e)
{
string sFile = "~/Attachments/"+(e.CommandArgument.ToString());
if(File.Exists(Server.MapPath(sFile)))
{
Response.Redirect("/Forms/DownloadFile.aspx?file="+sFile); //ERROR HERE
}
}
DownloadFile.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
string sPath = Server.MapPath(Request.QueryString["file"]);
FileInfo file = new FileInfo();
if(file.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition","attachment; filename="+file.Name);
Response.AddHeader("Content-Length",file.Length.ToString());
Response.ContentType="application/octet-stream";
Response.WriteFile(file.FullName);
Response.End();
}
}
DownloadFile.aspx uses the same Master and has the code. There is no problem when downloading from Tickets.aspx. I thought this could be due to the iframe. So I created a similar download page without a master. But still the same error.
How can I resolve this.