Thursday, March 29, 2012

Newbie: I need some tips

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??

JeffUsing 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

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)

"Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
news:%23KAabkfWFHA.3716@.TK2MSFTNGP12.phx.gbl...
> 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

0 comments:

Post a Comment