在我们的项目中,我们有一个管理应用程序和一个客户端应用程序。 管理员应用程序用于管理所有客户端。
因此,当我登录到服务器应用程序时,管理员凭据将保存在会话中。
之后我在另一个浏览器中访问了客户端应用程序。它包含下载功能。下载后发生的事情是它清除所有会话数据。因此,每次下载后我都需要在管理模块中再次登录。
下载处理程序
if (context.Request["fileUrl"] != null)
{
fileUrl = context.Request["fileUrl"].ToString();
}
string filename = System.IO.Path.GetFileName(fileUrl);
context.Response.ClearContent();
context.Response.ContentType = "application/exe";
context.Response.AddHeader("content-disposition", String.Format("attachment; filename={0}", filename));
context.Response.TransmitFile(fileUrl);
context.Response.Flush();
我使用iframe进行下载。所以我会在点击下载按钮时设置iframe的来源
代码隐藏文件
iframeDownload.Attributes["src"] = "DownloadHandler.ashx?fileUrl=" + downloadUrl;
//code to be executed after download
//here i am enabling a timer control
但我无法找到为什么在下载后会话被清除。 我在这篇SO帖子中发现了类似的问题。 Session expires after file download
但对他而言,它只发生在IE中,但就我而言,它发生在所有浏览器中。
答案 0 :(得分:1)
实际上,在成功下载后我的代码中,我们需要从我的应用程序中删除一个文件夹。这会导致重新启动App_domain。
参考:SO帖子Delete Directory from ASP.NET application returns to new session。