beginners help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Luke Smith

    #1

    beginners help

    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(Applicatio n("Counter_" + counterid));
    // Get the counter ID (unique to each counter in the site)
    if (Session("Count erTemp_" + 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(se rver.mappath(co unterid + ".txt")))
    {
    StreamReader sr = File.OpenText(s erver.mappath(c ounterid + ".txt"));
    ivalue = cint(sr.ReadLin e().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.Loc k();
    Application("Co unter_" + counterid) = ivalue.ToString ();
    Application.UnL ock();
    // Save counter to a text file
    FileStream fs = new FileStream(serv er.mappath(coun terid + ".txt"),
    FileMode.Create , FileAccess.Writ e);
    StreamWriter sw = new StreamWriter(fs );
    sw.WriteLine(Co nvert.ToString( ivalue));
    sw.Close;
    fs.Close;
    // Set a session variable so this counter doesn't fire again in the current
    session
    Session.Add(("C ounterTemp_" + counterid), "True");
    }
    }
    }
    }


  • Dmitriy Lapshin [C# / .NET MVP]

    #2
    Re: beginners help

    Hi Luke,

    You obviously miss the following line:

    using System.Web;

    --
    Dmitriy Lapshin [C# / .NET MVP]
    X-Unity Test Studio

    Bring the power of unit testing to VS .NET IDE

    "Luke Smith" <luke.smith99@b tinternet.com> wrote in message
    news:e3gAisVtDH A.2448@TK2MSFTN GP09.phx.gbl...[color=blue]
    > i have the following code in counter.cs but i get errors regarding[/color]
    request,[color=blue]
    > application, session. I know im missing something but dont know what it[/color]
    is.[color=blue]
    >
    > 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(Applicatio n("Counter_" + counterid));
    > // Get the counter ID (unique to each counter in the site)
    > if (Session("Count erTemp_" + 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(se rver.mappath(co unterid + ".txt")))
    > {
    > StreamReader sr = File.OpenText(s erver.mappath(c ounterid + ".txt"));
    > ivalue = cint(sr.ReadLin e().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.Loc k();
    > Application("Co unter_" + counterid) = ivalue.ToString ();
    > Application.UnL ock();
    > // Save counter to a text file
    > FileStream fs = new FileStream(serv er.mappath(coun terid + ".txt"),
    > FileMode.Create , FileAccess.Writ e);
    > StreamWriter sw = new StreamWriter(fs );
    > sw.WriteLine(Co nvert.ToString( ivalue));
    > sw.Close;
    > fs.Close;
    > // Set a session variable so this counter doesn't fire again in the[/color]
    current[color=blue]
    > session
    > Session.Add(("C ounterTemp_" + counterid), "True");
    > }
    > }
    > }
    > }
    >
    >[/color]

    Comment

    Working...