T
Thomas Coleman
Ok, I've obviously discovered that Global.aspx has been completely changed in
..NET 2.0. However, I haven't figured out how to declare a constant that's
available to any page in my application without having to jump through a bunch
of hoops.
First, let me layout how it worked in 1.1. In the Global.asax, within the Global
class construct, I would simply add something like:
public const string FOO = "foo";
Now, anywhere in any page, I could do something like:
Session[Global.FOO] = "bar";
Some people have suggested using an Application level variable (or in Cache).
However, that presents it's own problem. For example, suppose we have:
Application["Foo"] = "foo";
How do I use intellisense with the indexer name? The answer is that I cannot. If
I type:
Application["Foolish"] = "foo";
That will compile and I only get an error a runtime.
So, having intellisense to global/application wide constant is a must.
Some other suggestions that I have seen:
1. Create a new base class for every page where the variable is declared.
The problem here is that my developers have to remember to inherit from this
specific base class for all pages. In addition, it complicates things when I use
master pages
2. Declare the variable in a Master page which is used by every page.
Obviously, this is similar to the above idea. The problem here is multiple
master pages complicates the issue.
3. Create a static class and add a reference every it is needed.
Yes, I could do this. But it seems highly untidy given that this is such a
common need.
4. Fiddle with HttpHanders/HttpModules.
Don't know enough about how to go about doing this for global constants. Seems
like overkill.
Declaring universally used constants is pretty common IMO. So what is the
simplest way of doing this?
Thomas
..NET 2.0. However, I haven't figured out how to declare a constant that's
available to any page in my application without having to jump through a bunch
of hoops.
First, let me layout how it worked in 1.1. In the Global.asax, within the Global
class construct, I would simply add something like:
public const string FOO = "foo";
Now, anywhere in any page, I could do something like:
Session[Global.FOO] = "bar";
Some people have suggested using an Application level variable (or in Cache).
However, that presents it's own problem. For example, suppose we have:
Application["Foo"] = "foo";
How do I use intellisense with the indexer name? The answer is that I cannot. If
I type:
Application["Foolish"] = "foo";
That will compile and I only get an error a runtime.
So, having intellisense to global/application wide constant is a must.
Some other suggestions that I have seen:
1. Create a new base class for every page where the variable is declared.
The problem here is that my developers have to remember to inherit from this
specific base class for all pages. In addition, it complicates things when I use
master pages
2. Declare the variable in a Master page which is used by every page.
Obviously, this is similar to the above idea. The problem here is multiple
master pages complicates the issue.
3. Create a static class and add a reference every it is needed.
Yes, I could do this. But it seems highly untidy given that this is such a
common need.
4. Fiddle with HttpHanders/HttpModules.
Don't know enough about how to go about doing this for global constants. Seems
like overkill.
Declaring universally used constants is pretty common IMO. So what is the
simplest way of doing this?
Thomas