tags:

views:

49

answers:

3

I need to run some code that will fetch some configuration values from the web.config during first run of an asp.net mvc application. These values will not change frequently but that is not my main concern.

One way that I can think of is calling the method in Application_Start() method in the global.asax.cs file, but I am hoping someone has a better idea.

A: 

That is what I would recommend, do you have something against that?

If you explain a little more about what you are trying to accomplish, we may be able to help more.

Dustin Laine
A: 

I think that is pretty standard.

http://weblogs.asp.net/rashid/archive/2009/02/17/use-bootstrapper-in-your-asp-net-mvc-application-and-reduce-code-smell.aspx

(Not a link to what I'd call a "recommended approach," just something that demonstrates that Application_Start is the jumping off point for all sorts of configuration and initialization.)

Jay
+1  A: 

Application start was really created for purposes like that. If you are just populating things from the Web.Config why not create a class that pulls them directly from there if you are worried about abstraction? It's already cached by ASP.Net, so you aren't paying a penalty from accessing the web.config multiple times. This way you don't have to worry about using the Global.Asax which you seem to be against.

If you are really against using the Global.Asax, you could always have a method that checks to see if they are loaded on the landing page on your site, or have a method in the master page that fires each time a page using it is accessed. I would still use the Global.asax Application_Start or Session_Start myself though.

Kevin
You could also wrap the settings in a property and only load them on demand: the lazy load pattern.
Adrian K
I guess I didnt explain myself well, but I am not against using Application_Start(),I just thought there could be a better alternative.The reason I want to do this is because I am implementing a custom membership provider, and the more I get into it I get the feeling I am better of implementing the functionality myself altogether.As the membership provider gets config values via the base class, and that I believe is implemented in an http module, I thought if would simulate similar behavior once at the start of the application.You seem to have confirmed my original plan, so I will follow it.TA
Nosh