I have a hit counter in asp.net 2.0 but when i apply it to a asp.net 3.5 web page(aspx and .vb code separet file) it doesnot work. my 2.0 page is as under.
<%@ Import Namespace="System.IO" %>
<%@ Page Language="VB"%>
<html>
<head>
<title>Hit Counter</title>
<script language=VB runat="server" id="count">
Sub Page_Load(Src as object, E as EventArgs)
dim objReader as StreamReader
dim objWriter as StreamWriter
dim sFile as string
dim sCount as string
dim iCount as integer
Try
sFile = Server.MapPath(".")
If Right(sFile, 1) <> "\" Then sFile = sFile & "\"
sFile = sFile & "counter.txt"
If not File.Exists(sFile) then
objWriter = File.CreateText(sFile)
objWriter.Write("0")
objWriter.Close
End if
objReader = File.OpenText(sFile)
sCount = objReader.ReadToEnd()
objReader.Close
iCount = Cint(sCount)
iCount = iCount + 1
sCount = iCount.ToString
objWriter = File.CreateText(sFile)
objWriter.Write(sCount)
objWriter.Close
Catch Ex as Exception
Label1.width = New Unit(640)
sCount = "[Count could not be obtained due to the following error]: " & Ex.Message
Finally
Label1.Text = sCount
End Try
End Sub
</script>
</head>
<BODY>
<p>
<img src="abhi.JPG" style="font-size: 10pt; width: 139px;
font-family: Verdana; height: 174px;" /> </p>
<p>
<span style="font-size: 10pt; font-family: Verdana">
Thank you for visiting ....</span></p>
<p>
<a href="http://www.itorian.com">Blog Page</a></p>
<p>
<span style="font-size: 10pt; font-family: Verdana; color: #ff0033;"><strong>
You are our visitor number : </strong></span>
<asp:label id=Label1 runat="server" Height="21px" Width="57px" Font-Bold="True" Font-Size="X-Large" ForeColor="Blue"></asp:label></p>
<p>
</p>
</BODY></html>
I applied the above code in asp.net 3.5 (aspx and vb code speparate)
.vb FILE
Sub Page_Load(Src as object, E as EventArgs)
dim objReader as StreamReader
dim objWriter as StreamWriter
dim sFile as string
dim sCount as string
dim iCount as integer
Try
sFile = Server.MapPath(".")
If Right(sFile, 1) <> "\" Then sFile = sFile & "\"
sFile = sFile & "counter.txt"
If not File.Exists(sFile) then
objWriter = File.CreateText(sFile)
objWriter.Write("0")
objWriter.Close
End if
objReader = File.OpenText(sFile)
sCount = objReader.ReadToEnd()
objReader.Close
iCount = Cint(sCount)
iCount = iCount + 1
sCount = iCount.ToString
objWriter = File.CreateText(sFile)
objWriter.Write(sCount)
objWriter.Close
Catch Ex as Exception
Label1.width = New Unit(640)
sCount = "[Count could not be obtained due to the following error]: " & Ex.Message
Finally
Label1.Text = sCount
End Try
End Sub
.aspx FILE
<p>
<span style="font-size: 10pt; font-family: Verdana; color: #ff0033;"><strong>
You are our visitor number : </strong></span>
<asp:label id=Label1 runat="server" Height="21px" Width="57px" Font-Bold="True" Font-Size="X-Large" ForeColor="Blue"></asp:label></p>
<p>
Please help me do complete it. while browsing it no error is displyed but counter is not working. counter.txt file is added to my web
I don't think that is problem because i executed same code on 3.5 . You can check you application folder for counter.txt.I mean just to verify whether file is getting created or not.File which you are creating saves visit number. Her is source code which
worked for me.
Imports System.IO
Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim objReader As StreamReader
Dim objWriter As StreamWriter
Dim sFile As String
Dim sCount As String
Dim iCount As Integer
Try
sFile = Server.MapPath(".")
If Right(sFile, 1) <> "\" Then sFile = sFile & "\"
sFile = sFile & "counter.txt"
If Not File.Exists(sFile) Then
objWriter = File.CreateText(sFile)
objWriter.Write("0")
objWriter.Close()
End If
objReader = File.OpenText(sFile)
sCount = objReader.ReadToEnd()
objReader.Close()
iCount = CInt(sCount)
iCount = iCount + 1
sCount = iCount.ToString
objWriter = File.CreateText(sFile)
objWriter.Write(sCount)
objWriter.Close()
Catch Ex As Exception
Label1.width = New Unit(640)
sCount = "[Count could not be obtained due to the following error]: " & Ex.Message
Finally
Label1.Text = sCount
End Try
End Sub
End Class
Marked as answer by Baiju EP on Aug 08, 2012 04:32 PM
I am using WINXP3 with IIS in a local intranet web site. i browsed a lot and not found a solution for Specify an Identity for an Application Pool
please guide me.
I have a hit counter in asp.net 2.0 but when i apply it to a asp.net 3.5 web page(aspx and .vb code separet file) it doesnot work. my 2.0 page is as under.
<%@ Import Namespace="System.IO" %>
<%@ Page Language="VB"%>
<html>
<head>
<title>Hit Counter</title>
<script language=VB runat="server" id="count">
Sub Page_Load(Src as object, E as EventArgs)
dim objReader as StreamReader
dim objWriter as StreamWriter
dim sFile as string
dim sCount as string
dim iCount as integer
Try
sFile = Server.MapPath(".")
If Right(sFile, 1) <> "\" Then sFile = sFile & "\"
sFile = sFile & "counter.txt"
If not File.Exists(sFile) then
objWriter = File.CreateText(sFile)
objWriter.Write("0")
objWriter.Close
End if
objReader = File.OpenText(sFile)
sCount = objReader.ReadToEnd()
objReader.Close
iCount = Cint(sCount)
iCount = iCount + 1
sCount = iCount.ToString
objWriter = File.CreateText(sFile)
objWriter.Write(sCount)
objWriter.Close
Catch Ex as Exception
Label1.width = New Unit(640)
sCount = "[Count could not be obtained due to the following error]: " & Ex.Message
Finally
Label1.Text = sCount
End Try
End Sub
</script>
</head>
<BODY>
<p>
<img src="abhi.JPG" style="font-size: 10pt; width: 139px;
font-family: Verdana; height: 174px;" /> </p>
<p>
<span style="font-size: 10pt; font-family: Verdana">
Thank you for visiting ....</span></p>
<p>
<a href="http://www.itorian.com">Blog Page</a></p>
<p>
<span style="font-size: 10pt; font-family: Verdana; color: #ff0033;"><strong>
You are our visitor number : </strong></span>
<asp:label id=Label1 runat="server" Height="21px" Width="57px" Font-Bold="True" Font-Size="X-Large" ForeColor="Blue"></asp:label></p>
<p>
</p>
</BODY></html>
I applied the above code in asp.net 3.5 (aspx and vb code speparate)
.vb FILE
Sub Page_Load(Src as object, E as EventArgs)
dim objReader as StreamReader
dim objWriter as StreamWriter
dim sFile as string
dim sCount as string
dim iCount as integer
Try
sFile = Server.MapPath(".")
If Right(sFile, 1) <> "\" Then sFile = sFile & "\"
sFile = sFile & "counter.txt"
If not File.Exists(sFile) then
objWriter = File.CreateText(sFile)
objWriter.Write("0")
objWriter.Close
End if
objReader = File.OpenText(sFile)
sCount = objReader.ReadToEnd()
objReader.Close
iCount = Cint(sCount)
iCount = iCount + 1
sCount = iCount.ToString
objWriter = File.CreateText(sFile)
objWriter.Write(sCount)
objWriter.Close
Catch Ex as Exception
Label1.width = New Unit(640)
sCount = "[Count could not be obtained due to the following error]: " & Ex.Message
Finally
Label1.Text = sCount
End Try
End Sub
.aspx FILE
<p>
<span style="font-size: 10pt; font-family: Verdana; color: #ff0033;"><strong>
You are our visitor number : </strong></span>
<asp:label id=Label1 runat="server" Height="21px" Width="57px" Font-Bold="True" Font-Size="X-Large" ForeColor="Blue"></asp:label></p>
<p>
Please help me do complete it. while browsing it no error is displyed but counter is not working. counter.txt file is added to my web
Baiju EP
Member
176 Points
425 Posts
HIT COUNTER IN ASP.NET 3.5+VB
Aug 07, 2012 01:44 PM|LINK
I have a hit counter in asp.net 2.0 but when i apply it to a asp.net 3.5 web page(aspx and .vb code separet file) it doesnot work. my 2.0 page is as under.
<%@ Import Namespace="System.IO" %> <%@ Page Language="VB"%> <html> <head> <title>Hit Counter</title> <script language=VB runat="server" id="count"> Sub Page_Load(Src as object, E as EventArgs) dim objReader as StreamReader dim objWriter as StreamWriter dim sFile as string dim sCount as string dim iCount as integer Try sFile = Server.MapPath(".") If Right(sFile, 1) <> "\" Then sFile = sFile & "\" sFile = sFile & "counter.txt" If not File.Exists(sFile) then objWriter = File.CreateText(sFile) objWriter.Write("0") objWriter.Close End if objReader = File.OpenText(sFile) sCount = objReader.ReadToEnd() objReader.Close iCount = Cint(sCount) iCount = iCount + 1 sCount = iCount.ToString objWriter = File.CreateText(sFile) objWriter.Write(sCount) objWriter.Close Catch Ex as Exception Label1.width = New Unit(640) sCount = "[Count could not be obtained due to the following error]: " & Ex.Message Finally Label1.Text = sCount End Try End Sub </script> </head> <BODY> <p> <img src="abhi.JPG" style="font-size: 10pt; width: 139px; font-family: Verdana; height: 174px;" /> </p> <p> <span style="font-size: 10pt; font-family: Verdana"> Thank you for visiting ....</span></p> <p> <a href="http://www.itorian.com">Blog Page</a></p> <p> <span style="font-size: 10pt; font-family: Verdana; color: #ff0033;"><strong> You are our visitor number : </strong></span> <asp:label id=Label1 runat="server" Height="21px" Width="57px" Font-Bold="True" Font-Size="X-Large" ForeColor="Blue"></asp:label></p> <p> </p> </BODY></html>I applied the above code in asp.net 3.5 (aspx and vb code speparate)
.vb FILE
Sub Page_Load(Src as object, E as EventArgs) dim objReader as StreamReader dim objWriter as StreamWriter dim sFile as string dim sCount as string dim iCount as integer Try sFile = Server.MapPath(".") If Right(sFile, 1) <> "\" Then sFile = sFile & "\" sFile = sFile & "counter.txt" If not File.Exists(sFile) then objWriter = File.CreateText(sFile) objWriter.Write("0") objWriter.Close End if objReader = File.OpenText(sFile) sCount = objReader.ReadToEnd() objReader.Close iCount = Cint(sCount) iCount = iCount + 1 sCount = iCount.ToString objWriter = File.CreateText(sFile) objWriter.Write(sCount) objWriter.Close Catch Ex as Exception Label1.width = New Unit(640) sCount = "[Count could not be obtained due to the following error]: " & Ex.Message Finally Label1.Text = sCount End Try End Sub.aspx FILE
<p> <span style="font-size: 10pt; font-family: Verdana; color: #ff0033;"><strong> You are our visitor number : </strong></span> <asp:label id=Label1 runat="server" Height="21px" Width="57px" Font-Bold="True" Font-Size="X-Large" ForeColor="Blue"></asp:label></p> <p>Please help me do complete it. while browsing it no error is displyed but counter is not working. counter.txt file is added to my web
shabirhakim1
Star
13496 Points
2145 Posts
Re: HIT COUNTER IN ASP.NET 3.5+VB
Aug 07, 2012 02:24 PM|LINK
Hi,
I don't think that is problem because i executed same code on 3.5 . You can check you application folder for counter.txt.I mean just to verify whether file is getting created or not.File which you are creating saves visit number. Her is source code which worked for me.
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebApplication10._Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <p> <span style="font-size: 10pt; font-family: Verdana; color: #ff0033;"><strong> You are our visitor number : </strong></span> <asp:label id=Label1 runat="server" Height="21px" Width="57px" Font-Bold="True" Font-Size="X-Large" ForeColor="Blue"></asp:label></p> </div> </form> </body> </html>Imports System.IO Public Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim objReader As StreamReader Dim objWriter As StreamWriter Dim sFile As String Dim sCount As String Dim iCount As Integer Try sFile = Server.MapPath(".") If Right(sFile, 1) <> "\" Then sFile = sFile & "\" sFile = sFile & "counter.txt" If Not File.Exists(sFile) Then objWriter = File.CreateText(sFile) objWriter.Write("0") objWriter.Close() End If objReader = File.OpenText(sFile) sCount = objReader.ReadToEnd() objReader.Close() iCount = CInt(sCount) iCount = iCount + 1 sCount = iCount.ToString objWriter = File.CreateText(sFile) objWriter.Write(sCount) objWriter.Close() Catch Ex As Exception Label1.width = New Unit(640) sCount = "[Count could not be obtained due to the following error]: " & Ex.Message Finally Label1.Text = sCount End Try End Sub End ClassBaiju EP
Member
176 Points
425 Posts
Re: HIT COUNTER IN ASP.NET 3.5+VB
Aug 08, 2012 04:32 PM|LINK
Thanks a lot.it really works when i browse my web through VS 2008. when i publish the following error comes
[Count could not be obtained due to the following error]: Access to the path 'c:\inetpub\wwwroot\123\counter.txt' is denied.
I think there is some write permission to counter.txt file. how can i solve it
Baiju EP
Member
176 Points
425 Posts
Re: HIT COUNTER IN ASP.NET 3.5+VB
Aug 09, 2012 05:02 PM|LINK
I solved it
1> Right click on upload folder. Click on properties.
2> Click on Security tab.
3> Click on Add button
4> Write the Everyone in the “Enter the objecdt names to select[Select]:” textarea.
5> Click on Check Name button and click on ok button.
6> Give full control rights to this Everyone user.
ryanbesko
Contributor
3561 Points
619 Posts
Re: HIT COUNTER IN ASP.NET 3.5+VB
Aug 09, 2012 07:51 PM|LINK
You should not give permissions to everyone. The only thing that needs permission is the identity your application pool in IIS is using.
Baiju EP
Member
176 Points
425 Posts
Re: HIT COUNTER IN ASP.NET 3.5+VB
Aug 10, 2012 07:53 AM|LINK
I am using WINXP3 with IIS in a local intranet web site. i browsed a lot and not found a solution for Specify an Identity for an Application Pool please guide me.
ryanbesko
Contributor
3561 Points
619 Posts
Re: HIT COUNTER IN ASP.NET 3.5+VB
Aug 10, 2012 01:07 PM|LINK
Please see my answer in this post.
http://forums.asp.net/t/1769531.aspx/1?help+with+connection+string+for+newly+created+database+in+SQLExpress
tola_cis
Member
8 Points
4 Posts
Re: HIT COUNTER IN ASP.NET 3.5+VB
Nov 06, 2012 08:57 AM|LINK
Hii
Am not professional on The ASP.net with Vb
but i have the same code here for the Hit counter but this error is appear and i can not solve it
0000
Count could not be obtained due to the following error
Can you please help me in this
thank you alot
tola_cis
Member
8 Points
4 Posts
Re: HIT COUNTER IN ASP.NET 3.5+VB
Nov 12, 2012 07:38 AM|LINK