0

I have an application where I am making a call to a webmethod from Js.

 $.ajax({
    type: "POST",
    url: "mypage.aspx/MyWebMethod",
    ....
    ....
    });

In my C# webmethod I have set

[WebMethod(EnableSession = true)]

The problem is very strange and I donot even know if it is a Jquery or C# or server setting problem.

Problem: When I run the webpage and start using the application, everything working fine. However, if I just keep the webpage open (for something like 5 min) and donot do anything with it..and then try to use the application, the ajax call fails.

Can someone please let me know what the problem could be?

5
  • 1
    Ok, try this: Start the server (F5), and do your ajax call. Then wait 5 minutes, or however long it took for it to stop working, and then try opening a page on your server, and see if it loads. Then, without refreshing your first page, do the ajax call, and see if it works. Commented Aug 26, 2012 at 12:01
  • 1
    you're using a webmethode with EnableSession=true and your session might been expired after 5 min for that reason your ajax call fails consider making the expiry date of your session more longer Commented Aug 26, 2012 at 12:34
  • @Sora ... how do I make the session last longer..? Commented Aug 26, 2012 at 12:50
  • change the expiry date in your web.config file do some search in google :) Commented Aug 26, 2012 at 12:51
  • The problem was with the session variables which are being wiped off every 10 min or so..I couldnot set the time to higher value even through global.asax...therefore I stored the session variable which was not very sensitive in a hidden variable and used it.. Commented Aug 26, 2012 at 15:03

2 Answers 2

1

I strongly recommend you change this:

[WebMethod(EnableSession = true)]

To this:

HttpContext.Current.Session

That way you don't need to use (EnableSession = true) I tested my own and there is no problem

Good luck!

Sign up to request clarification or add additional context in comments.

Comments

0

Its likely that the ASP Session is expiring, and you are getting an HTTP 401 or similar.

You can either handle the in your ajax error{} callback, or alternatively consider various workarounds for keeping the session alive in the background.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.