AJAX and Forms Authenication Timeout

Discussion in 'ASP .Net' started by Angel666, Jan 16, 2008.

  1. Angel666

    Angel666 Guest

    We are using forms authenication with AJAX update control panels. We
    get various results but no redirect when the user has timed out and is
    no longer authenicated and does a asyncpostback. We have tried
    onasyncpostbackerror method but it is not even hitting the code
    behind.
    Because the server does try to redirect to login page we get the
    parser error(below) as it is trying to parse the login page in the
    background.


    Sys.WebForms.PageRequestManagerParserErrorException: The message
    received
    from the server could not be parsed. Common causes for this error are
    when
    the response is modified by calls to Response.Write(), response
    filters,
    HttpModules, or server trace is enabled.


    Details: Error parsing near ' |<html>


    <head>

    Is there any solution for authenication time out with the Update panel
    usage that can do a redirect on asynchpostbacks??
    Thank you
    Joe
     
    Angel666, Jan 16, 2008
    #1
    1. Advertisements

  2. Angel666

    bruce barker Guest

    using a cutom OnAuthenicate, you could detect it was an async postback
    (check for "X-MicrosoftAjax" header), and respond with an ajax compatiable
    error response, instead of redirecting to the login page.

    -- bruce (sqlwork.com)
     
    bruce barker, Jan 16, 2008
    #2
    1. Advertisements

  3. Angel666

    Angel666 Guest

    Let me clarify. We are using standard .Net forms authenication. Users
    login fine but it is once we are in the application.

    A user waits pass the timeout then interacts with a page inside the
    application that has an update panel
    and we get the famous PageMgrParser problem because what is being sent
    via the response is the login page as it should.
    Problem is response doesnt know how to handle this so blows up. We
    tried onAsychPostBackError but the code behind doesnt even get hit.

    Any ideas?
     
    Angel666, Jan 16, 2008
    #3
  4. Angel666

    starsky163

    Joined:
    Oct 17, 2008
    Messages:
    2
    Likes Received:
    0
    client side handler

    Add a client side event handler for EndRequest. Place this code after your ScriptManager tag and perform whatever redirection you want....

    /* get this page's PageRequestManager and add a handler to get the response from the server */
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    function EndRequestHandler(sender, args)
    {
    if (args.get_error() != undefined)
    {
    var errorMessage = args.get_error().message;
    var statusCode = args.get_response().get_statusCode();
    if (statusCode == '0' || statusCode == '12030' || statusCode == '12031')
    { /* timeout or server N/A - second two are MS proprietary */
    window.location.pathname = '/Login.aspx?ReturnUrl=' + window.location.pathname;
    }
    else
    {
    alert(errorMessage);
    }
    args.set_errorHandled(true);
    }
    }
    /* notify script manager that script has been loaded (add this only if you have it in an external file) */
    if (typeof(Sys) != 'undefined') Sys.Application.notifyScriptLoaded();
     
    starsky163, Oct 20, 2008
    #4
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.