Newbie: I need some tips

J

Jeff

IDE vs .NET 2003
OS: XP pro sp2

I need to create a asp.net page which will receive data sent to it via
GET... The data sent into the page is a number, this number should be added
together with the numbers sent into the page by other users...

for example:
user A: http://localhost/test.aspx?value=1
and
user B: http://localhost/test.aspx?value=2

if user C want to retrieve this value, he should get the value 3 (1 +2)

Here som of the code in my Global.asax.cs:
public class Global : System.Web.HttpApplication
{
/// <summary>
/// Required designer variable.
/// </summary>
///
int b;

protected void Application_Start(Object sender, EventArgs e)
{
b ++;
Application.Add("test", b);
}

As you can see from my code above, I'm trying to fix this problem using
HttpApplication... Is that the correct approach? If it isn't, what is the
correct approach then??

Jeff
 
K

Karl Seguin

Using Application is fine...but you should be putting it in the
Application_BeginRequest method, or the Page_Load of test.
Application_Start fires once and only once so it'll never add. It's hard to
advise without knowing more in detail. I'd be tempted to scoping this out
to the test.aspx page.

The following code will in no way compile, but should give you a general
idea

page_load
int userInput;
try{
userInput = Int32.Parse(Request.QueryString["value"]);
}catch (Exception ex){
if (!(ex is FormatException) && !(ex is InvalidCastException) && !(ex
is OverflowException))
throw;
}
object o = Application["totalCount"]
if (Application["totalCount"] != null){
((int)Application["totalCount"]) += userInput
}else{
Application["totalCount"] = userInput;
}

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top