Error occurring when Forms Authentication has timed out

Last post 09-22-2010, 8:43 PM by snagpoonage. 3 replies.
Sort Posts: Previous Next
  •  05-11-2010, 3:27 AM 60895

    Error occurring when Forms Authentication has timed out

    Hi,
    I've got a site using Forms Authentication and if I let the page time out, and then try to upload a file with Ajax Uploader (basic single file upload, upload type = auto) I get a large popup window error message that shows the message 'unknown result' and the HTML source of the page. When I check the server application event log it says "Forms authentication failed for the request. Reason: The ticket supplied has expired" - which is what I would expect.
     
    So, I'm wondering if there's a setting or a way to make Ajax Uploader check if the user is logged in before/after it uploads a file. I've tried checking if the user is logged-in in the Uploader_FileUploaded method but the error still occurs.
     
    Thanks.
  •  05-12-2010, 8:00 PM 60963 in reply to 60895

    Re: Error occurring when Forms Authentication has timed out

    If anybody is interested I found a way around this problem...
     
    I've ended up removing forms authentication from the page that contains the Ajax Uploader control, and I'm checking if the user is logged in manually and not using the Forms Authentication web.config value to protect that particular page. This allows me to use the OnFileValidating event to check if the user is logged in...
     

        protected void Uploader1_FileValidating(object sender, UploaderEventArgs args)
        {
            User _usrCurrent = ((BasePage)this.Page).CurrentUser;
            if (_usrCurrent.Id <= 0)
            {
                throw (new Exception("Your session has timed out - please log in again"));
            }
        }
     
    Not the cleanest solution - but it works!
     
  •  05-12-2010, 9:03 PM 60967 in reply to 60895

    Re: Error occurring when Forms Authentication has timed out

    Hi,
     
    Currently the uploader do not process the authentication redirecting issue.
     
    We will improve it later.
     
    For example , send idle AJAX request to keep the cookie,  and also show the friendly error if the auth expired
     
    Regards,
    Terry
  •  09-22-2010, 8:43 PM 64149 in reply to 60963

    Re: Error occurring when Forms Authentication has timed out

    Hi everyone,
     
    For anyone who does not wish to have the user logged out at all during a file upload you can use a script similar to below.
    1. var timeoutPeriod = 1;   
    2.         function refreshPage() {               
    3.             var decRound = Math.round(Math.random() * 1000);   
    4.             var imgRefresh = new Image(1, 1);   
    5.             imgRefresh.src = 'Keepalive.aspx?id=' + decRound.toString();   
    6.             timeoutWarning = setTimeout(refreshPage, timeoutPeriod * 30000);   
    7.         }  
    Put that into a script block in your upload page. There are many different ways to use this script, the basic principle remains the same. Firstly you need to create an empty aspx. I have called mine Keepalive.aspx. In this page you need to put the following:
    1. <%@ OutputCache Location="None" VaryByParam="None" %>  
    This will tell the browser basically not to cache the page so it must reload it each time. and thats it for the Keepalive page.  When the Image requests the Keepalive.aspx page, a request is sent to the server, and your forms authentication ticket is refreshed without changing anything in the broswer (I use this inside an UpdatePanel but I'm not sure how it works outside of one).
     
    Some things to note is the variable timeoutPeriod is set to 1, this equates to 30 seconds as set by setTimeout(refreshPage, timeoutPeriod * 30000), : 1ms * 30000 = 30000ms = 30s. So the timout refresh will be done every 30 seconds. To call this code you can either place a call to it within the body onload event, or alternately when you upload a file to the server.
     
    For the full article and reference for this post see http://www.codeproject.com/KB/aspnet/keepalive.aspx.
     
    I successfully use this technique with CuteSoft AJAX uploader.
     
    My settings are below:
     
    IIS 7.0, ASP.Net 3.5, AJAX Uploader PersistedFileUpload, Manual Upload, Inside an update panel.
View as RSS news feed in XML