我试图在一个pagerequest期间用livetime设置一个全局变量。在c#中设置全局变量class
在经典ALS我用这个像这样:
dim VariableName
VariableName = "test";
sub testsub()
VariableName += VariableName + "new"
response.write VariableName
end sub
response.write VariableName '-> test
testsub() '-> testnew
现在在asp.net我tryed设置变量在我的课是这样的:
public static class MyClass
{
public static string GlobalVar = "test";
public static string MyMethod()
{
GlobalVar += GlobalVar + "new";
return GlobalVar;
}
}
但是现在,问题是,这个变量就像一个应用变量,其生命周期超过了所有的pagerequest。
在哪里可以定义一个生命期间的变量,在一个请求期间可用于所有方法和其他类?
这有坏设计写在它上面 – 2009-12-28 12:53:34