0

In our project we have got a admin application and a client application. The admin application is used to manage all clients.

So when i logged in to server application , the admin credentials are saved in session.

After that i accessed client application in another browser. It contains a download functionality. After download what happens is that it clears all session data. So after each download i need to login again in the admin module.

Download handler

                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();

I have used an iframe to do the download. So i will set the source for iframe when download button is clicked

Code behind file

iframeDownload.Attributes["src"] = "DownloadHandler.ashx?fileUrl=" + downloadUrl;
//code to be executed after download
//here i am enabling a timer control

But i can't find why the session is cleared after this download. I found a similar issue in this SO post. Session expires after file download

But for him it happens only in IE, but in my case its happening in all browsers.

Community
  • 1
  • 1
Mahesh KP
  • 6,248
  • 13
  • 50
  • 71
  • 1
    Nothing in those lines of code would cause your sessions to be destroyed. Is your file too large? Causing the asp.net process to be recycled. – nunespascal Jul 24 '12 at 05:47
  • @nunespascal : No it didn't depend on the file.. it is happening in case of small file also.. – Mahesh KP Jul 24 '12 at 05:51
  • @nunespascal : i have a db update after that download, so after downloading i am updating a db value in the same button click. I think this will not affect any session recycle anyway.. – Mahesh KP Jul 24 '12 at 05:54
  • Is the other browser mean, you are trying to access it from a new instance different browser or from different machine? Also what session store you are using? – Ramesh Jul 24 '12 at 06:25
  • @Ramesh: i am accessing the admin side in firefox and client in chrome. Session is stored in application itself, i mean am not specifying any special session mode , so it must be InProc.. – Mahesh KP Jul 24 '12 at 06:30
  • @Ramesh : i have enabled a timer after that download, so when i comment that piece of code then session is there. – Mahesh KP Jul 24 '12 at 06:44
  • What does the time do? If there is any unhandled exception in background thread your IIS will recycle – Ramesh Jul 24 '12 at 06:48
  • @Ramesh : In the tick event it continuously checking a db value and updating in the website. No i can't find any exception there. – Mahesh KP Jul 24 '12 at 06:53
  • I am not finding it elegant. May be you need to find a another mechanism. May be where you are displaying the DB value is where you need to fetch it. Also, when is the timer stop ticking? For every download you are creating a new instance of a timer? – Ramesh Jul 24 '12 at 06:56
  • @Ramesh : Actually we are using the Timer Control in ajax extensions. Initially it will be disable and after download it is enabled. I am not finding any issue in this code. Actually the downloaded file is an exe and after its execution the timer get disabled. – Mahesh KP Jul 24 '12 at 07:00
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/14324/discussion-between-ramesh-and-mahesh) – Ramesh Jul 24 '12 at 07:01

1 Answers1

1

Actually in my code after the successful download we need to delete a folder from my application. This causes the restart of App_domain.

Ref: SO post Delete Directory from ASP.NET application returns to new session.

Community
  • 1
  • 1
Mahesh KP
  • 6,248
  • 13
  • 50
  • 71