简体   繁体   English

jQuery C#Web方法

[英]jquery c# webmethod

I have an application where I am making a call to a webmethod from Js. 我有一个应用程序,正在从Js调用Web方法。

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

In my C# webmethod I have set 在我的C#网络方法中,我已经设置

[WebMethod(EnableSession = true)]

The problem is very strange and I donot even know if it is a Jquery or C# or server setting problem. 这个问题非常奇怪,我什至不知道这是Jquery还是C#或服务器设置问题。

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. 但是,如果我只是保持网页打开(大约5分钟),并且不对其进行任何操作,然后尝试使用该应用程序,则ajax调用将失败。

Can someone please let me know what the problem could be? 有人可以让我知道可能是什么问题吗?

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 这样,您就不需要使用(EnableSession = true)我测试了自己的并且没有问题

Good luck! 祝好运!

Its likely that the ASP Session is expiring, and you are getting an HTTP 401 or similar. ASP会话可能即将到期,并且您收到的是HTTP 401或类似消息。

You can either handle the in your ajax error{} callback, or alternatively consider various workarounds for keeping the session alive in the background. 您可以处理ajax error{}回调,也可以考虑采用各种 变通办法来保持会话在后台运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM