Session changing when Response.Redirect in UploadCompleted is fired

Last post 05-13-2010, 3:58 AM by thomasm. 2 replies.
Sort Posts: Previous Next
  •  05-12-2010, 11:04 AM 60952

    Session changing when Response.Redirect in UploadCompleted is fired

    Hi there,
     
    In my Global.asax I am creating a session under session_start to initialise Session["Session_Id"] but for this example it is being initialised in the Page_Load.
     
    When a file has been uploaded, the UploadCompleted method is fired which then attempts to refresh the page. It's at this point that the Session "Session_Id" changes. Strangely, this only happens on the first attempt. Any attempts made after this will work and the session doesn't change. I don't want the Sessions value to change.
     
    I have attached a .net page called UploadTestPage.aspx which will demonstrate this.
     
    Another thing to mention is that this works fine on my Local machine but when put into a live environment it doesn't work. The live environment is using II6 and has been upgraded to .NET 4. My local environment is using Visual Studio 2010.
     
    Any help is appreciated! 
     
     ------------------------------------------------------------------------------
     
    <%@ Page Language="C#" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">

        void Page_Load(object sender, EventArgs e)
        {
            // Initialise the session if empty.
            if (Session["Session_Id"] == null)
            {
                Session["Session_Id"] = System.Guid.NewGuid();
            }

            // Display the session.
            Label1.Text = Session["Session_Id"].ToString();
        }

        void Uploader1_FileUploaded(object sender, CuteWebUI.UploaderEventArgs args)
        {
            // code to insert to database.
            // Taken out for this example.
        }

        void Uploader1_UploadCompleted(object sender, CuteWebUI.UploaderEventArgs[] args)
        {
            // When all files have been transfered, refresh the page.
            // It's at this point that the session id changes.
            Response.Redirect(Request.Url.ToString());
        }

        void Button1_Click(object sender, EventArgs e)
        {
            // Change the session.
            Session["Session_Id"] = Guid.NewGuid();
            // Refresh the page.
            Response.Redirect(Request.Url.ToString(), false);
        }
        
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <h1>
            Upload test</h1>
        <CuteWebUI:Uploader ID="Uploader1" InsertText="Upload your images" MultipleFilesUpload="true"
            MaxFilesLimit="10" OnFileUploaded="Uploader1_FileUploaded" ShowProgressInfo="false"
            AutoUseSystemTempFolder="true" ValidateOption-AllowedFileExtensions="jpg,png,gif,bmp"
            runat="server" OnUploadCompleted="Uploader1_UploadCompleted">
        </CuteWebUI:Uploader>
        <div style="border: 1px solid #000;">
            <asp:Button ID="Button1" runat="server" Text="Change session" OnClick="Button1_Click" />
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        </div>
        </form>
    </body>
    </html>

     
    Filed under: ,
  •  05-12-2010, 9:08 PM 60968 in reply to 60952

    Re: Session changing when Response.Redirect in UploadCompleted is fired

    Hi,
     
    Since you said your code work locally, I think we will not able to reproduce it.
     
    Can you test this ? after file be uploaded , try add a new button
     
     
     void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect(Request.Url.ToString(), false);
        }
     
    Do not redirect it in Uploader1_UploadCompleted event.
     
    Or you can also try another way , select some files, and after the first file be uploaded , press F5 to refresh the page.
     
    Regards,
    Terry
     
  •  05-13-2010, 3:58 AM 60982 in reply to 60968

    Re: Session changing when Response.Redirect in UploadCompleted is fired

    Hi Terry,
     
    I have implemented the Button2 control and it's click method. I have also commented out the refresh page code in the OnUploadCompleted method.
     
    I have done some testing with this and have come up with some interesting results. These tests have been conducted by closing all browsers then opening up a fresh browser.
     
    Chrome 4.1                    = Session changes after refresh button clicked.
    FireFox v 3.6                   = Session changes after refresh button clicked.
    Internet Explorer 8         = Session stays the same after refresh button clicked.
     
    Have tried this with all Upload types ie Flash, Silverlight and the results are the same. I have also tested this on two seperate computers and the results were also the same.
     
    If there's anything else you want me to try let me know. 
View as RSS news feed in XML