Avatar of Feivi99
Feivi99

asked on 

implementing a giveaway in .net/c#

Hi everyone,

I'd like to implement a giveaway on mysite, whereby threel times a day a random visitor will receive a message that he won "xyz" (really!).

Is there a way to implement this without a database? I would need to be sure that only three people will get the message and not more!

Thanks in advance
.NET ProgrammingC#

Avatar of undefined
Last Comment
Alfred A.
Avatar of Imran Javed Zia
Imran Javed Zia
Flag of Pakistan image

Hi,
You can do so with following,

Add a counter in Application and just randomly chose one user.  // but there is a disadvantage of it, if your application restarts then it will restart the counter. you can avoid then by saving this counter with date in some file on the server.

Thanks
Avatar of Feivi99
Feivi99

ASKER

Hi IJZ,

I'm not sure what you meant with "add a counter in application".
Avatar of Alfred A.
Alfred A.
Flag of Australia image

Check this out regarding adding a counter in Application_OnStart event of the Global.asax file.

http://forums.asp.net/p/1509963/3594591.aspx
Avatar of Alfred A.
Alfred A.
Flag of Australia image

By the way, the sample in my previous post is for VB.NET.  Sorry.  The one below is C# inside a Global.asax file:
public class Global : System.Web.HttpApplication
    {
        protected void Application_Start(object sender, EventArgs e)
        {
            // Set our user count to 0 when we start the server
            Application["HitCounter"] = 0;
        }

        protected void Session_Start(object sender, EventArgs e)
        {
            Application.Lock();
            Application["HitCounter"] = (int)(Application["HitCounter"]) + 1;
            Application.UnLock();
        }

        protected void Session_End(object sender, EventArgs e)
        {
            Application.Lock();
            Application["HitCounter"] = (int)(Application["HitCounter"]) - 1;
            Application.UnLock();
        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }

Open in new window

Avatar of Feivi99
Feivi99

ASKER

Alfred,

Thanks for this code. There is one problem, however: I'm planning on serving the page from the ASP.NET cache, so I don't think Application_OnStart would work (I may be wrong). Do you know if this or any other event will fire when a page is served from cache?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Alfred A.
Alfred A.
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo