Hi,
create following class:
public class Ping
{
[AjaxMethod(HttpSessionStateRequirement.ReadWrite)]
public static bool Run()
{
return true;
}
}
Add the Utility.RegisterTypeForAjax(typeof(Ping)); in every page where
you want to run the ping, and add following code to your JavaScript
file:
function ping_callback(res) {
setTimeout(ping, 10*60*1000); // 10 minutes
}
function ping() {
Ping.Run(ping_callback);
}
ping_callback(null); // initial ping after 10 minutes
The 10 minutes have to be changed to your session timeout
configuration, a little less than this value.
You can put the class in a library project or in App_Code (.NET 2.0)
and you are happy with this.
Regards,
Michael
On 9/29/06, jrnail23 <[EMAIL PROTECTED]> wrote:
>
> Michael,
> I think I should also note that what I'm really trying to do is use
> Ajax to keep my ASP.NET session alive, by periodically "pinging" the
> "Ping.aspx" page from my application's other ASP.NET pages. While my
> app is in ASP.NET2.0, another one is in ASP.NET1.1 (I don't know about
> the App_Code folder in 1.1... does it even exist?).
>
> Thanks for any guidance you're able to provide.
>
> James
>
> jrnail23 wrote:
> > Hi Michael,
> > Thanks for the reply... I'm afraid that placing the AjaxMethod in a
> > class under the App_Code folder won't meet my needs, because I need the
> > AjaxMethod to read from my ASP.NET Session. Is there a way around
> > this, or am I mistaken entirely?
> >
> > Michael Schwarz wrote:
> > > Hi,
> > >
> > > I prefer to put the AjaxMethods in a seperate class and use only
> > > static methods. The problem is that the page is not yet compiled when
> > > writing your code.
> > >
> > > public class AjaxMethods
> > > {
> > > [AjaxMethod]
> > > public static string SayHell(string name)
> > > {
> > > return "Hello " + name;
> > > }
> > > }
> > >
> > >
> > > This class save in \App_Code and you are happy. Don't use the
> > > AjaxMethod in the same class as the Page.
> > >
> > > Regards,
> > > Michael
> > >
> > >
> > >
> > > On 9/28/06, jrnail23 <[EMAIL PROTECTED]> wrote:
> > > >
> > > > I'm trying to call an AJAX method from one page from another page, but
> > > > I can't seem to get the AjaxPro.Utility.RegisterTypeForAjax method to
> > > > work properly.
> > > >
> > > > The page I'm loading is Go_Scan (//Go/Scan.aspx)
> > > >
> > > > When I register that type within the page like this, everything is
> > > > fine:
> > > > AjaxPro.Utility.RegisterTypeForAjax(GetType(Go_Scan))
> > > >
> > > > Then, from the Scan.aspx page, I want to call an AJAX method located in
> > > > another page (//Go/Ping.aspx), so I use the RegisterTypeForAjax method
> > > > in Go_Scan's Page_Load event, like this:
> > > > AjaxPro.Utility.RegisterTypeForAjax(GetType(Go_Ping))
> > > >
> > > > With this, my code won't compile, and I can't seem to figure out how to
> > > > get it to work. I'm sure there's another way to reference the
> > > > Ping.aspx page, but I don't know how... can someone help me with this?
> > > >
> > > >
> > > > >
> > > >
> > >
> > >
> > > --
> > > Best regards | Schöne Grüße
> > > Michael
> > >
> > > Microsoft MVP - Most Valuable Professional
> > > Microsoft MCAD - Certified Application Developer
> > >
> > > http://weblogs.asp.net/mschwarz/
> > > http://www.schwarz-interactive.de/
> > >
> > > Skype: callto:schwarz-interactive
> > > MSN IM: [EMAIL PROTECTED]
>
>
> >
>
--
Best regards | Schöne Grüße
Michael
Microsoft MVP - Most Valuable Professional
Microsoft MCAD - Certified Application Developer
http://weblogs.asp.net/mschwarz/
http://www.schwarz-interactive.de/
Skype: callto:schwarz-interactive
MSN IM: [EMAIL PROTECTED]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ajax.NET Professional" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/ajaxpro
The latest downloads of Ajax.NET Professional can be found at
http://www.ajaxpro.info/
Don't forget to read my blog at http://weblogs.asp.net/mschwarz/
-~----------~----~----~----~------~----~------~--~---