Welcome to WebmasterWorld Guest from 126.96.36.199
Forum Moderators: ocean10000
I found a code example using asp.net and got it working very nicely in VWD on my computer. But when I loaded the code to my hosting server it fail. I found I had to make the directory which contain the page with the counter control read/write enabled. But I don't like using that setting for the pages that have all my webpages. I added a sub-directory, I called "Counter" I placed the counter.ascx file and the I use to store the count file in this directory. But I need to change one line of code in the counter.ascx file so that it will read and write to the counter file in the new directory. Right now it still wants to create/read/write the file in the same directory as the aspx file that calls the ascx file.
[b]strCountFileName = Server.MapPath(Request.ServerVariables("SCRIPT_NAME") & ".cnt")[/b][/2]
I think that "SCRIPT_NAME" is the name of the file that called the user control and that strCountFileName is the string variable that contains the complete path to the file that contains the current counter value.
In my case this is "..path\main.aspx.cnt" But now I what to make it equal to this "..path\Counter\main.aspx.cnt"
This should do the trick:
strCountFileName = Server.MapPath("~/Path/Counter/main.aspx.cnt")
* Edit - Forgot to add that the ~ means the root of the website, ie. if the control is located in
then the above line is correct.
Thank you for your reply.
In my example "Path/" was a fill in for the rest of the phyical path.
My testing shows that the count file that goes with the page that is being counted is created in the same directory as the aspx file (web root directory) and the ascx file is not in that directory, but in the counter directory. In my aspx file (main.aspx) I have the following lines of code.
<%@ Register TagPrefix="asp101" TagName="Counter" Src="Counter\counter.ascx" %>[/2]
<div style="background-image: url('images/Counter_BG.png'); width: 242px; height: 188px; text-align: center; vertical-align: middle; font-family: 'Comic Sans MS'; font-size: 24px; margin: 0 auto;">
<br /><br />
<span style="font-size: 48px;">
<asp101:Counter id="ctrlHitCounterText" runat="server"
Display = "text"
I think I can use your code example to hardcode the counter file for this web page, but I was wondering how I would make it possible to use it for any web page that used this asp101:Counter (object?)
<%@ Register TagPrefix="asp101" TagName="Counter" Src="Counter\counter.ascx" %>
You can change this to:
<%@ Register TagPrefix="asp101" TagName="Counter" Src="~/Counter/counter.ascx" %>
Assuming that ~/ is the root, as described in my previous post.
Add this to any page that you would like to use the control, and then use the code:
<asp101:Counter id="ctrlHitCounterText" runat="server" Display = "text"/>
to place the control in the desired position.
(I prefer the forward slash when pointing to a file or folder, as opposed to your example, but both should work)