Click here to Skip to main content
13,502,277 members
Rate this:
Please Sign up or sign in to vote.
See more:

We have a requirement in our Web application which needs to track individual user's No. of hits to web site and how much time he is spending in our site.

For that i got below idea,

1. When User session starts note down time as sTime
2. When User session ends note down time as eTime
3. subtract eTime-sTime as time
4. Pass user_name and time to some function in Class library which will insert into database table.

First three points i have completed 4th point i am unable to call that particular function from Global.asax where
functions are defined.

Please help me how i can call that function from
in Global.asax.

Posted 20-Dec-12 1:49am
sjelen 20-Dec-12 8:07am
What does 'unable to call' mean? Are you unable to build the code or are you getting errors/exceptions?
Or your function just does not get called?
Oleksandr Kulchytskyi 20-Dec-12 9:08am
Hi , Did you use the in-process session state mode ???
When the Session State Manager removes a session state object that resides in the cache, the HttpCache manager will call any registered callbacks. In effect, this behavior raises the Session_OnEnd event handler. (IN CASE of in-process session state mode!!!)
n.podbielski 20-Dec-12 17:20pm
Maybe your project is really a WebSite?
Suraj S Koneri 24-Dec-12 5:56am
Hi all, Thanks for all your replies.
@n.podbielski--Yes ofcourse im developing website only.
@Oleksandr Kulchytskyi - I am not aware about in-process session state mode. can you please put light on this.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

User.Identity.Name Will return domain\username


string domain = User.Identity.Name.Split('\\')[0];
string username = User.Identity.Name.Split('\\')[1];

Then call your function-

RecordTime(username, time);
Suraj S Koneri 24-Dec-12 6:07am
Thanks for your answer. My issue is not able to call xyz() function of class library in Session_End().
Even if i call it. when Session_End event fired also it is not calling that xyz().

Alternative way of getting user name is - Environment.UserName.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.180417.1 | Last Updated 21 Dec 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100