count the registered user to visited page and post in asp.net using sqlserver [Resolved]

Posted by Dn2010 under ASP.NET on 1/9/2011 | Points: 10 | Views : 4177 | Status : [Member] | Replies : 15
hi friends,

how to count the registered user to visited page and post in asp.net using sqlserver.

please give in detail.

thanks.




Responses

Posted by: Karthikanbarasan on: 1/10/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 50

Up
0
Down

Resolved
Hi Dn2010,

Is your issue solved, else take this code... this works as expected

copy this code in ur global.asax


void Application_Start(object sender, EventArgs e) {


// Code that runs on application startup

Application["activeuser"] = 0;
}

void Session_Start(object sender, EventArgs e) {

// Code that runs when a new session is started



Session["start"] = DateTime.Now;
Application.Lock();

Application["activeuser"] = Convert.ToInt32(Application["activeuser"]) + 1;


Application.UnLock();

}

in ur defalut.aspx

<% int i = Convert.ToInt32(Application["activeuser"]);
Response.Write(i.ToString());

%>

this will give the no of visitors in ur page


Thanks
Karthik
www.f5Debug.net

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 1/9/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi,

try the below code... with this you would also need to:

1) initialize all the urls during application loading time with something like Application["... each url... "] = 0;
2) consider concurrency issues and if you are taking into account anonymous users, enable session state for them
3) decrement the Session["previousUrl"]'s value in corresponding Application State when the users session ends.

string currentUrl = System.Web.HttpContext.Current.Request.Url.AbsolutePath;  

if (Session["previousUrl"] != null)
{
if (Session["previousUrl"] != currentUrl)
{
int urlNew = (int)Application[currentUrl];
urlNew++;
Application[currentUrl] = urlNew;

string previousUrl = (string)Session["previousUrl"];
int urlOld = (int)Application[previousUrl];
urlOld--;
Application[previousUrl] = urlOld;
}

}

Label1.Text = ((int)Application[currentUrl]).ToString();
Session["previousUrl"] = currentUrl;


Thanks
Karthik
www.f5Debug.net

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 1/9/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
There are many third party sites which give this solution as well and it will be more generic and shows the count and visitors based on the region

check this link below... this is one of the third party site which gives this solution

http://www.countertool.com/website-visitor-counters/?gclid=CKOZ3NW8raYCFQd76wodmhpdNQ

Thanks
Karthik
www.f5Debug.net

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dn2010 on: 1/9/2011 [Member] Starter | Points: 25

Up
0
Down
thanks for your response,

your reply is good,

but please give in detail.



Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 1/9/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
hi,

you want in detail abt the code or u want to know how to integrate the third party option with ur aspx page?

Thanks
Karthik
www.f5Debug.net

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 1/9/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
hi,

you want in detail abt the code or u want to know how to integrate the third party option with ur aspx page?

Thanks
Karthik
www.f5Debug.net

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dn2010 on: 1/9/2011 [Member] Starter | Points: 25

Up
0
Down
i want to detail about code,

thanks.

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 1/9/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi Dn2010,

Its difficult to explain the complete code here.... Check the below link it explains the same process step by step on how to store the visitors count and the process to save it in Sql db

http://imar.spaanjaars.com/238/howto-create-a-hit-counter-using-a-database-in-aspnet-1x-with-c-sharp

http://www.codegain.com/codesnippets/aspnet/howto/how-to-create-hit-counter-usercontrol-in-aspnet.aspx

Thanks
Karthik
www.f5Debug.net

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dn2010 on: 1/9/2011 [Member] Starter | Points: 25

Up
0
Down
thank you .

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 1/9/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Welcome... let me know if you could able to solve the issue with the above links... if not let me know the issue faced... thanks

Thanks
Karthik
www.f5Debug.net

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Suresh.mekkattil on: 1/9/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,

Create a Session variable and incriment the session value each time when the page get loaded.

Note: you need to be careful of one user visiting several time!!

-----
Suresh M

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dn2010 on: 1/10/2011 [Member] Starter | Points: 25

Up
0
Down
thanks,

please give the code for it.

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dn2010 on: 1/10/2011 [Member] Starter | Points: 25

Up
0
Down
thank you so much.

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikanbarasan on: 1/10/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Welcome...

Thanks
Karthik
www.f5Debug.net

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Padmachava111 on: 6/24/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

How can we find how many times a particular user visted the website and what all the links he/she visted.

and count need to post into sqlserver.




Thanks in advance.

Dn2010, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response