We help IT Professionals succeed at work.

jquery ajax problem (un autherized) in asp.net web page

njgroup
njgroup asked
on
Medium Priority
2,650 Views
Last Modified: 2012-04-10
hi,

I have ajax method using jquery and it works so fine, but after some time of keeping the page opened, if I click the button (to request web method from server) I got this error message in firebug:

JSON:
Message
      "Authentication failed."
      
StackTrace
      null
      
ExceptionType
      "System.InvalidOperationException"

Response:
{"Message":"Authentication failed.","StackTrace":null,"ExceptionType":"System.InvalidOperationException"}


so how can I fix this problem?
Comment
Watch Question

Meir RivkinFull stack Software Engineer
CERTIFIED EXPERT

Commented:
what is the statusCode returned? is it 401?
if u refresh the page are you able to make it run?

Author

Commented:
yes, if I refresh the page, its gonna run fine
Full stack Software Engineer
CERTIFIED EXPERT
Commented:
this is due to session timeout in ajax calls.
you can either customize your ajax response instead of throwing 401 exception:
http://stackoverflow.com/questions/5238854/handling-session-timeout-in-ajax-calls

or, redirect to the login page or to increase expiration session timeout in your web.config or preventing session timeout altogether:
http://xpapad.wordpress.com/2010/06/19/preventing-session-expiration-with-ajax/

for each one of the solution proposed you need to understand the implications first,

cheers