.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Losing Session after redirect.

Posted By:      Posted Date: September 19, 2010    Points: 0   Category :ASP.Net

Hello everyone.


I am having an issue with a piece of code. Everything else on the site works perfect except for this part.
Basically, there is a button on a page that says 'Download images', what this does is compress a list of files and then redirects the user to the .zip file.

EDIT: The problem I am having is as soon as the 'Download Images' button is clicked and they are prompted to download the file their session is lost. It does not matter if they download the file or not, as soon as the button is hit the file copy process takes at most 10 seconds and then the download box is shown.

Here is the code on the 'Download Images' button:


Dim bpoClass As New BpoClass


Response.Redirect("zipfiles/" & Request.QueryString("UniqueID") & ".zip")


Now, if I comment out the bpoclass.compresszipfile function, it works; the session is not lost. So it  might have something to do with the code inside the fu

View Complete Post

More Related Resource Links

Losing Session Data with Response.Redirect


This is weird. In my newly developed chat application, when I invoke Response.Redirect, I am losing my session data. What is particualrly odd is that this sometimes seems to occur after a slight delay, so I reach the page, and then the session info gets lost momentarily thereafter. Mostly though it seems to get lost immediately. I have of course googled this issue, but yet to find anything that speaks to my problem. SessionState is in InProc mode. Session state has been working fine for me until this unexpected problem, so everything is configured right. So far the only workaround I can think of is to use a link instead of a button, and use javascript to call a server-side function on onclick to do the work I need to do before the link gets invoked. Messy, and I'd rather not go that way unless there's no alternative.

Just to preempt one red herring, I do use Response.Redirect(<address>, false).

The problem occurs both on the testing and production servers. I'm running ASP.NET 3.5 on IIS7.

HTTPContext.Current.Session losing the variable sporatically

I have noticed a strange behaviour in my ASP.net 2.0 application. I have some logic in my aspx page that accesses some Session variables fine, then accesses some app_code and most of the time the HTTPContext.Current.Session returns the variable back fine.  However, I have noticed that sometimes this Session returns null, like it has lost it's "pointer" to the current HTTPContext. Is this a known bug, has anyone seen something like this before?   Any help would be appreciated, thanks, Mark. 

how to redirect user to login page if session is null

i have 2 page,1.login.aspx ---  2.welcome.aspxin my login.aspx im storing username into sesssion as below:Session["usernm"] = txtUsername.Text;in my welcome.aspx  pagein page_load event if (Session["usernm"]==null)        {            Response.Redirect("Login.aspx");        }----- here if i manulally paste the url ( http://localhost:4125/Loginado/welcome.aspx) it should go to  login.aspx for user credentialsbut its going directly to welcome.aspx  page.

How to catch error in session variable in globals.asax(Application_Error) and redirect to same page

Hi, i have a login page where username got to enter his/her username or password. When you try to enter any scripting over there eg:'<asd>' it gives an error  'Server Error in '/' Application' 'A Potentially dangerous Request. Form value was detected from client' I don't want to redirect user to custom error page when such unpredictable error occurs. infact i got a label on the same page itself where error's are displayed. how can i display such errors on this very same label. can i do that using globals Application_Error ?. Session variable not working here. Please give me the exact steps for how i can catch and display the error which are not validated. waiting for reply thanks and regards, Learning Programmer

Set session Timeout and Auto Redirect



I am creating web application. In that I want to set session timeout (not idle timeout). If a user logged in that time the session time will start and it automatically should detect session timeout the page should redirect to another page. How can I acheive this.

Session time out alert box and redirect login page


Dear all,

Now I am using Form authentication for my website. 

It is something like that below. But if I left the website without using it for quite some time and when I used it back, it is redirected to the login page. 

The one I want to know is that it is because of session expire or cookies expire. And if it is session expired, I want to show the alert box and redirect to the login page. And one more thing is that if the user keeps on using the website, I want to extend the session expire time. If you do not mind, I want to have some references for this scenario. Thank you so much.


If myUser.IsValidUser(txtUserName.Text.Trim, txtPassword.Text.Trim) = True Then

User keeps losing Session on Anonymous site?


This code was working before, but something has changed and I don't know what.  I have an anonymous registration page.  On it, I have a CAPTCHA image, with a URL pointing to an ASPX page that is generating the image.  On the Registration page I am generating a 6 digit code to be displayed in the CAPTCHA image, then saving it to a Session variable.  On the CAPTCHA ASPX page, I am grabbing that Session variable and creating the image.  However, the Session is resetting when the CAPTCHA ASPX page is called.  If I debug it, it has a different ID and the variable is gone.

Why is this happening and how can I fix it?  I have Sessions enabled in SharePoint 2007.

Can I only create session on login and redirect to login from other apps if not using custom provide


I have created custom a MembershipProvider, SessionIDManager, and SessionStateStore since I need to use custom legacy sessions and logins.. When the Application is ran, it runs the GetSessionID in the SessionIDManager(which is correct)..

The problem then is if there is no session meaning the GetSessionID method returns null, it tries to create a new session using CreateSessionID.. I want it to redirect to the login application(another application)..

We only create and store session information for logged in users and the "session id numbers" come from a file that is pre-populated with "session id numbers"(I didnt design this and its out of my control).. So its not feasable to give everyone who visits the site one of the "session id" numbers..

I also need for users with an "invalid" session(when checked through Validate()) to be redirected to the login page..


Any help here would be great..

session timeout redirect in ajax calls


If a normal session timeout occurs we could handle the session timeout.

But say we are using a lot of ajax calls, webhandlers etc. How would we catch session timeout here and redirect to error/login page.


redirect asp.net website having Sessions from localhost by passing the session values


hi friends

             I want to open a web site in code by giving the server url, but in that server page we are restricting if session is null. Is work the session passing from the localhost in server???

How to pass session from local host to server



Why do session variables disappear on redirect between pages in IFrame?


I have a web site A with IFrame linked to web site B. A and B are located on different servers. B site has several pages (BHome, B1, B2).
When B site redirects from BHome page to Bx all session variables get cleared.

I can’t find why all session variables disappear.

Do you have any ideas?

redirect from Application_AuthenticateRequest in global.asax in session time out



i want to redirect the user from ?????the ??AuthenticateRequest in the global.asax file when session timeout ?happens.

is it possible.





Auto logout and redirect to login page when session expires using asp.net

In this article I will explain you how to auto logout and redirect to login page when users session expires within specific period.

MS SQL Server: Disconnect Users From Database - Kill User Session

If you ever wanted to restore your database from a SQL backup file (.bak), but there are still users connected to your database, the backup operation will fail causing the error: Exclusive access could not be obtained because the database is in use.

Response.Redirect slow


I'm in the middle of migrating servers and on the new server Response.Redirect is extremely slow. It takes around 20 seconds for the browser to get the redirect. This is something that was quick on the existing server. It's an ASP.NET 2.0 application, both servers are running IIS6.

Additionally, if I "manually" do the redirect, it's fast. For example:

Existing way:


takes around 20 seconds on the new server

New way:

Response.Status = "302 Moved Temporarily";
Response.AddHeader("Location", url);

is fast on the new server.

Any ideas why Response.Redirect would be so slow on the new server?

Automatically redirect to HTTPS and check if SSL is active



I've set in the web.config:

    <!-- User Authentication -->
    <authentication mode="Forms">
      <forms loginUrl="~/Page/View/Content/Login.aspx" timeout="2880" requireSSL="true" />

This works fine. If there is no ssl connection, the login form doesn't continue. But I would like to check if ssl is active (in codebehind) and, if it's possible, to automatically the user to the https page if he's currently on http. (I could do this job by manually redirect with page.response("https://url.../login.aspx"); but this is not really generic. For example if the webapp is moved to another domain it doesn't work anymore... I'm looking for something like: FormsAuthentication.RedirectWithSSL(); or so... :D)


Profile not being save after redirect.



I am trying to save values into a Profile on Page1, then redirect to Page2 and access those values.  However, after the page redirects the profile values are blank as if they were never saved.   When stepping through the code I can see that they are being save on Page 1.

I suppose I could use session variables to store the information but I don't understand why saving the profile doesn't work.

private void PayWithPayPal()
        ProfileCommon profile = this.Profile;

        if (Global.CurrentUserName.Length > 0)
            profile = this.Profile.GetProfile(Global.CurrentUserName);
        profile.FirstName = uxFirstNameShipping.Text;
        profile.LastName = uxLastNameBilling.Text;
        profile.ShippingAddress.AddressLineOne = uxAddressLineOneShipping.Text;
        profile.ShippingAddress.AddressLineTwo = uxAddressLineTwoShipping.Text;
        profile.ShippingAddress.City = uxCityShipping.Text;
        profile.ShippingAddress.State = uxStateShipping.Text;
        profile.ShippingAddress.ZipCode = uxPostalCodeShipping.Text;

        Response.Redirect("~/expresspayment.aspx", false);

protected void Page_Load(object sender, EventArgs e)
        ProfileCommon p
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend