Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

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
C#
Session_Start 
and
C#
Session_End 
functions are defined.

Please help me how i can call that function from
C#
Session_End() 
in Global.asax.

Thanks,
Posted
Comments
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

User.Identity.Name Will return domain\username

therefore:


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

Then call your function-

RecordTime(username, time);
 
Share this answer
 
v2
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900