• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1149
  • Last Modified:

ASP.net Global.aspx

I read from the web.config in my global.aspx. How can I get this variable from my form?

protected void Application_Start(Object sender, EventArgs e)
{
   propertyId = ConfigurationSettings.AppSettings.Get("ID");      
}
0
jeremiahscott
Asked:
jeremiahscott
  • 2
  • 2
1 Solution
 
sforcierCommented:
Have you tried:

propertyId = ConfigurationSettings.AppSettings("ID");
0
 
jeremiahscottAuthor Commented:
yea, i call that once when my app starts up in global.aspx. should i just call that each time from my form instead? is it costly to do that?
0
 
sforcierCommented:
You could do the following:

'in global.asax
protected void Application_Start(Object sender, EventArgs e)
{
   Application["propertyId"] = ConfigurationSettings.AppSettings.Get("ID");    
}

'in any webform
int x = Application["propertyId"]; //Assuming it's an integer, you get the idea

You mention the alternative of loading from the webconfig in the form itself, which is actually what I'd recommend (conditionally). Using application variables uses memory, and unless you're using this propertyId on every web form, you're wasting memory by loading it in an application variable.
0
 
jeremiahscottAuthor Commented:
gotcha. thx!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now