Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm putting together a site using Asp.NET MVC with Entity Framework.

I need to pull in my configuration row from its table when the site launches.

Is this something that I can do in the App_Start, the Home Controller or something else entirely?

Thanks
Ger
Posted

1 solution

Got it myself
I put this function in global_asax and called it from Application_start:
C#
 private void getConfig()
 {
              EFConfigRepository configRepository = new EFConfigRepository();
//  const string sessionKey = "Config";
  CConfigMasterBase config = null;
  config = configRepository.Config
            .FirstOrDefault();
  System.Web.HttpContext.Current.Application["_Config"] = config;


 }


Then called it like this from the cshtml:
C#
@{
    CConfigMasterBase config = new CConfigMasterBase();
    config = (CConfigMasterBase)System.Web.HttpContext.Current.Application["_Config"];
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900