0

I use ASP.net Web Forms and C#.

I have a page A with a method X.

I need call the method X when a User from page A visit any other pages outside A or log-out from my Web Application.

My questions:

  • What is the right event to use?
  • How to implement it?

Please provide me an example of code.

Thanks for your help!

GibboK
  • 71,848
  • 143
  • 435
  • 658

2 Answers2

2

Almost by definition, this is not an event on your website. It is an event on the browser, however. JQuery/Javascript is a good way to go:

Detect when a user leaves a website

Community
  • 1
  • 1
Kieren Johnstone
  • 41,277
  • 16
  • 94
  • 144
  • I need a solution with MS Tool Box, not other libraries... Any ideas? thanks for your comment on this. – GibboK Jul 04 '11 at 11:14
  • 3
    There is no built-in ASP.NET method for detecting when a user goes to an external site or closes a window. You need to use Javascript for that, and even then it's not foolproof. – Kieren Johnstone Jul 04 '11 at 11:15
  • 1
    JavaScript has been supported by MS for many, many years, and JQuery is now included in all new projects created in Visual Studio, and has been officially supported (i.e. you can phone them up and say "It's all broken, help!) for a couple of years now, so I'd say that both JS and JQuery are in the "MS Tool Box". – Zhaph - Ben Duguid Jul 04 '11 at 11:38
-2

Probably you can add Global.asax file to your web site project. Then try implementing the logic of method X in the Application_BeginRequest event handler. In this handler you can sniff the requests, so that you know what page was requested by the client (works only if the pages are IN your web app :))