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

Redirect during callback

10 Answers 546 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 1
Adam asked on 12 Sep 2011, 02:40 PM
I've got a FileExplorer page that presents users with the files in their home directory using the Custom File Provider example. It works great. However, I'm doing checks to make sure that a person has logged in through our system to make sure they are authenticated so I can show them their home directory.

Since the FileExplorer uses callbacks, doing a response.redirect to the login page gives the "Response.Redirect cannot be called in a Page callback." error.

Originally, I was using this:

Response.Redirect(ConfigurationManager.AppSettings("SSOLogin") & "?Source=" & Request.Url.ToString)

I then changed it to:
If Page.IsCallback Then
   Response.Clear()
   Response.StatusCode = 302
   Response.Status = "302 Moved Temporarily"
   Response.RedirectLocation = ConfigurationManager.AppSettings("SSOLogin") & "?Source=" & Request.Url.ToString
   Response.End()
Else
   Response.Redirect(ConfigurationManager.AppSettings("SSOLogin") & "?Source=" & Request.Url.ToString)
End If
However, the FileExplorer doesn't appear to redirect correctly. The test I am performing is simply clicking on a folder in the left hand menu while being logged out. It correctly gives me back the 302 status code and the Location header, but FileExplorer just keeps spinning on the grid side as if it's going to do something. I'm doing most of the testing in IE9.

Any suggestions???
Adam

10 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 14 Sep 2011, 10:31 AM
Hi Adam,

I searched in Google and found the following forum thread which could be helpful for your scenario:
response.redirect cannot be called in a callback call.

Kind regards,
Rumen
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal
0
Adam
Top achievements
Rank 1
answered on 14 Sep 2011, 02:30 PM
Yes, I've read that post. What's interesting is that the code I have works when doing regular callbacks using the AjaxManager and it redirects perfectly. However, with the FileExplorer it does not work. Obviously the FileExplorer is not the same as the AjaxManager, but I figured the method would be very similar and would work there as well.
0
Adam
Top achievements
Rank 1
answered on 14 Sep 2011, 02:33 PM
Is there a client side method of the FileExplorer that gets called every time a callback occurs. I'm thinking I may have it do a quick callback before doing something, like opening a folder, to see if the user is still logged in. If they aren't, I can then cancel the event that was going to fire and redirect them from client side code instead of trying to inject some client side code from code behind during the callback.

Alternatively, if there is a method for injecting client side code from code behind through the FileExplorer, that might work as well.

Thanks,
Adam
0
Dobromir
Telerik team
answered on 19 Sep 2011, 09:52 AM
Hi Adam,

RadFileExplorer does not offer specific client-side or server-side event that is raised when the control initiates a callback. However, I believe that you can use the RadFileExplorer's server-side events to check if the session is expired.

Regards,
Dobromir
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal
0
Adam
Top achievements
Rank 1
answered on 30 Sep 2011, 05:18 PM
Essentially I'm doing that. When it does it's callback, I am checking to see if their session has expired. The problem is that I don't have a mechanism to redirect the user to a login page when it's in the middle of a callback. If it were a postback, the response.redirect would work fine.
0
Dobromir
Telerik team
answered on 03 Oct 2011, 02:18 PM
Hi Adam,

The only operation that it is not possible to call Response.Redirect is when a folder is loaded inside the grid of RadFileExplorer. To handle this command you can use OnClientFolderLoaded client-side event of the explorer to check for the session cookie.

Kind regards,
Dobromir
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Adam
Top achievements
Rank 1
answered on 04 Oct 2011, 03:50 PM
Unfortunately, that even fires after it's already attempted to load up the directory contents. What end ups happening is:
  1. Users authentication expires (or the log out on a separate page).
  2. They click a different directory.
  3. RadFileExplorer attempts to load the directory but gets a callback error.
  4. The OnClientFolderLoaded event should fire, but doesn't due to the callback error.

Instead of using OnClientFolderLoaded, I ended up using a combination of OnClientFolderChange and OnClientFileOpen since they occur before the callback.

When a user selects a different folder in the treeview, OnClientFolderChange is executed and I'm making a web request to a handler that checks to see if they are still logged in. If they are, it continues, and if not, it redirects them to the login page.

In the OnClientFileOpen, I'm doing the same thing, but only if what they are trying to open is a directory by checking the isDirectory() flag. It appears that in both cases a callback is produced.

Thanks,
Adam

0
Dobromir
Telerik team
answered on 05 Oct 2011, 08:03 PM
Hi Adam,

I am not quite sure I have understand your last reply. Did you managed to redirect the user to a different page handling the OnClientFolderChange and OnClientFileOpen events?

Are you trying to achieve this server-side? If so, it seems that I was not clear enough in my previous answer. By suggesting to handle the client-side events of the RadFileExplorer to achieve this I meant, that you should redirect the user using JavaScript - by setting window.location to the starting / logging page ,e.g.:
function OnClientFolderChange(explorer, args)
{
 
    //add custom code to assign boolean value to userIsLogged variable
 
    if(!userIsLogged)
    {
        window.location = ./login.aspx
    }
}


Kind regards,
Dobromir
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Adam
Top achievements
Rank 1
answered on 05 Oct 2011, 08:50 PM
I've got it working. I'm doing a callback to a handler to verify that they are still logged in. If they are, it lets the operation continue, and if they aren't, it redirects them using javascript to the login page. I have to check on the server to see if they are logged in. The cookie doesn't determine it.
0
Dobromir
Telerik team
answered on 05 Oct 2011, 10:20 PM

OK Adam, I will consider this issue resolved.

Regards,
Dobromir
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
FileExplorer
Asked by
Adam
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Adam
Top achievements
Rank 1
Dobromir
Telerik team
Share this question
or