This is a migrated thread and some comments may be shown as answers.

Preupload Validation

3 Answers 76 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Kyle
Top achievements
Rank 1
Kyle asked on 14 Oct 2010, 04:51 PM
Is it possible to do a preupload validation that requires server-side code?

For example, I want to make sure that a variable is in session before the upload continues.  We have users that go thru our upload process, get to the end (which removes all session variables), then they click Back on their browser and try to do another upload.  Doing so causes a NullReferenceException.

I'd like to check to see if the session variable exists.  If it does, allow the upload to continue.  If not, forward them to a new page telling them their session has expired.

Any ideas would be greatly appreciated.

Thanks,
Kyle

3 Answers, 1 is accepted

Sort by
0
Accepted
Cori
Top achievements
Rank 2
answered on 14 Oct 2010, 06:35 PM

Hello Kyle,

If they are pressing the back button, you can't do a server-side check for the variable since the broswer is using cached version of your page, so no postback is made. You could most add an Ajax call in that page, which would run when the page is loaded, since that should be called during this kind of situation and redirect them to the page saying their session has expired.

To do what I just described, add a RadAjaxManager control on the page and then use its ajaxRequest client-side method to make an ajax call. In the code-behind handle the AjaxRequest event and redirect them if the session doesn't exist.

So something like this:

JavaScript:

$telerik.$(document).ready(function(){$find("<%=RadAjaxManager1.ClientID %>").ajaxRequest("CheckSession");});

Code-Behind:

protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
    {
        if (e.Argument == "CheckSession")
        {
            // check session code goes here
  
            // redirect user if it fails
            RadAjaxManager1.Redirect("SessionExpired.aspx");
        }
    }

I hope that helps.

0
Kyle
Top achievements
Rank 1
answered on 14 Oct 2010, 06:57 PM
That's a good idea.  I didn't think about doing a check at page load via AJAX.  I was thinking about using an AJAX call to a WebMethod when the user clicked Upload.  I guess that's what happens when you have blinders on.

The other thought I had was to try setting Response.Cache.SetCacheability(HttpCacheability.NoCache);  I haven't tested this yet, but I'm going to try that first.

Thanks for the help!
0
Cori
Top achievements
Rank 2
answered on 15 Oct 2010, 01:13 PM
Yeah, I was going to suggest setting a response header, but I thought you wanted the ability to use the back button. If you want to prevent them from pressin back, I would set the Expires response header to a day or hour in the past or the current time, I'm not really sure, but you can test it out, so the browser will not try load the page again. It will just say the page expired, like you see on some governement or ticket web sites.

I hope that helps.
Tags
Upload (Obsolete)
Asked by
Kyle
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
Kyle
Top achievements
Rank 1
Share this question
or