beginners help

  • Thread starter Thread starter Luke Smith
  • Start date Start date
L

Luke Smith

i have the following code in counter.cs but i get errors regarding request,
application, session. I know im missing something but dont know what it is.

thnx

using System.IO;
namespace luke_smith
{
/// <summary>
/// Summary description for counter.
/// </summary>
public class counter
{
public counter()
{
int counterid = request("id");
int iValue = cint(Application("Counter_" + counterid));
// Get the counter ID (unique to each counter in the site)
if (Session("CounterTemp_" + counterid) == Nothing)
{
// If the text file exists load the saved value
// Always loading it from the file rather than just using the application
variable allows for manual modification of counter values while the
application is running (by editing the text file). To stop it from being
able to be modified just uncomment the following 'if..then' and the 'end
if'. This will give a slight performance boost to the counter incrementing
as it will stop a file operation. Yes, I'm an optimization freak! :)
//if value = 0 then
if (File.Exists(server.mappath(counterid + ".txt")))
{
StreamReader sr = File.OpenText(server.mappath(counterid + ".txt"));
ivalue = cint(sr.ReadLine().ToString());
sr.Close;
}
// Increment counter
ivalue =++ 1;
// Save counter to an application var (the locks are there to make sure
noone else changes it at the same time)
Application.Lock();
Application("Counter_" + counterid) = ivalue.ToString();
Application.UnLock();
// Save counter to a text file
FileStream fs = new FileStream(server.mappath(counterid + ".txt"),
FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(Convert.ToString(ivalue));
sw.Close;
fs.Close;
// Set a session variable so this counter doesn't fire again in the current
session
Session.Add(("CounterTemp_" + counterid), "True");
}
}
}
}
 
Hi Luke,

You obviously miss the following line:

using System.Web;
 
Back
Top