471,317 Members | 1,588 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,317 software developers and data experts.

global.asax for non-page inheriting objects

Hi folks,

I'm not really sure of the terminology here, so I'll try my best.

I have been using global.asax to set up application variables that are
used within my applications, but for obvious (or not so) reasons the
application variables can only be accessed from objects that extend the
Page object.

So my question is, is there any way of storing variables (say database
connection data that I don't want hard-coded into the assembly) in an
external file like global.asax that can be accessed by any object?

If it helps to mention it, I am stilling using .net 1.1.

TIA

--
Dylan Parry
http://webpageworkshop.co.uk -- FREE Web tutorials and references

Disclaimer: This post does not represent the opinion of me or my cats.
Jan 20 '06 #1
5 1092
Dylan Parry wrote:
Hi folks,

I'm not really sure of the terminology here, so I'll try my best.

I have been using global.asax to set up application variables that are
used within my applications, but for obvious (or not so) reasons the
application variables can only be accessed from objects that extend the
Page object.

So my question is, is there any way of storing variables (say database
connection data that I don't want hard-coded into the assembly) in an
external file like global.asax that can be accessed by any object?

If it helps to mention it, I am stilling using .net 1.1.


Web.config?
--
Tom Porterfield
Jan 20 '06 #2
Hello Dylan,

Actually Application variables can be accessed by any in-process object,
i.e. any object running under the same process as the application. To store
hard coded data, the best place would be Web.config though.

HTH,
r.

Hi folks,

I'm not really sure of the terminology here, so I'll try my best.

I have been using global.asax to set up application variables that are
used within my applications, but for obvious (or not so) reasons the
application variables can only be accessed from objects that extend
the Page object.

So my question is, is there any way of storing variables (say database
connection data that I don't want hard-coded into the assembly) in an
external file like global.asax that can be accessed by any object?

If it helps to mention it, I am stilling using .net 1.1.

TIA

Disclaimer: This post does not represent the opinion of me or my cats.

Jan 20 '06 #3
Pondering the eternal question of "Hobnobs or Rich Tea?", Tom
Porterfield finally proclaimed:
Web.config?


Sounds like as good a place as any, but how would I go about using
web.config for this purpose? I've used it for things like password
protecting directories and changing the error reporting etc, but not for
something like this.

--
Dylan Parry
http://electricfreedom.org -- Where the Music Progressively Rocks!

Disclaimer: This post does not represent the opinion of me or my cats.
Jan 20 '06 #4
It is very easy to have objects that do not derive from Page class to use
Application state:

public class Class1
{
public string ConnectionString;
public Class1()
{
this.ConnectionString
=(string)HttpContext.Current.Application["connectionString"];

}
}

What you might do here is have an appSettings section in your web.config,
and in Application_Start in Global, set an Application["connectionString"]
variabl to this.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Dylan Parry" wrote:
Hi folks,

I'm not really sure of the terminology here, so I'll try my best.

I have been using global.asax to set up application variables that are
used within my applications, but for obvious (or not so) reasons the
application variables can only be accessed from objects that extend the
Page object.

So my question is, is there any way of storing variables (say database
connection data that I don't want hard-coded into the assembly) in an
external file like global.asax that can be accessed by any object?

If it helps to mention it, I am stilling using .net 1.1.

TIA

--
Dylan Parry
http://webpageworkshop.co.uk -- FREE Web tutorials and references

Disclaimer: This post does not represent the opinion of me or my cats.

Jan 20 '06 #5
Pondering the eternal question of "Hobnobs or Rich Tea?", Peter Bromberg
[C# MVP] finally proclaimed:
=(string)HttpContext.Current.Application["connectionString"];


Oh thanks, I didn't know you could do it like that! :)

--
Dylan Parry
http://webpageworkshop.co.uk -- FREE Web tutorials and references

Disclaimer: This post does not represent the opinion of me or my cats.
Jan 20 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

25 posts views Thread by Sahil Malik [MVP] | last post: by
25 posts views Thread by Sahil Malik [MVP] | last post: by
8 posts views Thread by Rob T | last post: by
8 posts views Thread by Rob T | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.