如何在Asp,NET MVC中加载配置行 [英] How do I load a configuration row in Asp,NET MVC
本文介绍了如何在Asp,NET MVC中加载配置行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Asp.NET MVC和Entity Framework组建一个站点。
当站点启动时,我需要从其表中提取配置行。
我可以在App_Start,Home Controller或其他东西中做些什么吗?
谢谢
Ger
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
推荐答案
自己动手
我把这个函数放在global_asax中并从Application_start中调用它:
Got it myself
I put this function in global_asax and called it from Application_start:
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;
}
然后从cshtml中调用它:
Then called it like this from the cshtml:
@{
CConfigMasterBase config = new CConfigMasterBase();
config = (CConfigMasterBase)System.Web.HttpContext.Current.Application["_Config"];
}
这篇关于如何在Asp,NET MVC中加载配置行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文