Ajax PageMethods and Session Timeouts

Last post 05-12-2008 12:47 AM by decrypted. 2 replies.

Sort Posts:

  • Ajax PageMethods and Session Timeouts

    05-08-2008, 11:07 PM
    • Loading...
    • decrypted
    • Joined on 05-08-2008, 10:57 PM
    • Posts 2

    I have a scenario where I am using PageMethods in javascript which invokes a static webmethod in the code behind. If the PageMethod is invoked after a session is timed out, I can validate the session, but since I have no handle to the actual Page, I'm unable to re-direct the user to the Login page. I can of course throw a custom "SessionExpiredException" back to javascript, handle it with a OnFailure delegate on window.location = 'login.aspx', but unfortunately I inherited a site with about 300 of these types of calls and growing - so I don't think it's a great design decision to leave the control decisions up to javascript.

     At best I have been able to enable forms authentication in the web.config, but it's super iffy and when it does work, gives a Kerbose style login prompt instead of a redirection.

    Am I just missing something fundemental here, or are other people in the same position with using PageMethods?

     Thanks in advance!

  • Re: Ajax PageMethods and Session Timeouts

    05-09-2008, 4:09 PM
    Answer

    decrypted,

    I really don't think you can do this without involving some javascript.  Your page method is basically a web service that returns a soap message.  It can't act on the DOM.  So you'll have to have a script that analyzes the message from your PageMethod and then acts on the page DOM -- for instance using window.location = 'redirectpage' in an error delegate, as you suggested -- to make this work.

    If you have the same method being called from lots of pages, this might be a good opportunity to pull it all out into a separate javascript file, where your logic will be centralized.  It's a pain now, but should make future maintenance much easier.

    James

    James Ashley, Magenic Technologies
    (james.ashley.magenic@gmail.com)
  • Re: Ajax PageMethods and Session Timeouts

    05-12-2008, 12:47 AM
    • Loading...
    • decrypted
    • Joined on 05-08-2008, 10:57 PM
    • Posts 2

    James,

     Yeah I knew there wasn't going to be any simple aproach. I'm thinking it would be either a client side solution whereby all PageMethods are intercepted before being sent to the server and checking against some sort of client side 'timout manager' (which I would assume would require extending ajax extensions) - or getting more tricky in the isapi filter chain......time to pull up my sleves and have some fun.

Page 1 of 1 (3 items)