code_junkie

Extending Forms Authentication Timeout When Making AJAX Calls With jQuery

Nov 13th, 2011
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. $.ajax('ajax.php',{timeout: 60000},function (data) {
  2. alert(data);
  3. }
  4.  
  5. <WebMethod(CacheDuration:=0, EnableSession:=True)> _
  6. Public Function keepSessionAlive() As String
  7. If Session("UID") Is Nothing OrElse Session("UID") = 0 Then
  8. Throw New ApplicationException("Login")
  9. End If
  10.  
  11. Session("lastKeepSessionAlive") = DateTime.Now
  12.  
  13. If Not (Context.Request.Cookies(System.Web.Security.FormsAuthentication.FormsCookieName) Is Nothing) Then
  14. Dim ticket As System.Web.Security.FormsAuthenticationTicket
  15. Try
  16. ticket = System.Web.Security.FormsAuthentication.Decrypt(Context.Request.Cookies(System.Web.Security.FormsAuthentication.FormsCookieName).Value)
  17. If ticket.Name = Context.Session("UID") Then
  18. System.Web.Security.FormsAuthentication.SetAuthCookie(Context.Session("UID"), False)
  19. Debug.WriteLine("keepAlive:AuthenticationReset")
  20. End If
  21. Catch ex As Exception
  22. Debug.WriteLine("keepAlive:AuthenticationReset FAILED!!!")
  23. Throw New ApplicationException("Login")
  24. End Try
  25. Else
  26. Debug.WriteLine("keepAlive.Load: No Authentication Cookie. Error")
  27. Throw New ApplicationException("Login")
  28. End If
  29.  
  30. Return Session.SessionID.ToString
  31. End Function
Add Comment
Please, Sign In to add comment