Redirect during callback

11 posts, 0 answers
  1. Adam
    Adam avatar
    177 posts
    Member since:
    Oct 2012

    Posted 12 Sep 2011 Link to this post

    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
  2. Rumen
    Admin
    Rumen avatar
    12846 posts

    Posted 14 Sep 2011 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Adam
    Adam avatar
    177 posts
    Member since:
    Oct 2012

    Posted 14 Sep 2011 Link to this post

    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.
  5. Adam
    Adam avatar
    177 posts
    Member since:
    Oct 2012

    Posted 14 Sep 2011 Link to this post

    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
  6. Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 19 Sep 2011 Link to this post

    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
  7. Adam
    Adam avatar
    177 posts
    Member since:
    Oct 2012

    Posted 30 Sep 2011 Link to this post

    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.
  8. Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 03 Oct 2011 Link to this post

    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
  9. Adam
    Adam avatar
    177 posts
    Member since:
    Oct 2012

    Posted 04 Oct 2011 Link to this post

    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

  10. Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 05 Oct 2011 Link to this post

    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
  11. Adam
    Adam avatar
    177 posts
    Member since:
    Oct 2012

    Posted 05 Oct 2011 Link to this post

    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.
  12. Dobromir
    Admin
    Dobromir avatar
    1633 posts

    Posted 05 Oct 2011 Link to this post


    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017