Windows Azure读取配置文件

在传统的ASP.NET应用程序里,我们读取的配置文件一般都是放在Web.config,并且通过

System.Configuration.ConfigurationSettings.AppSettings[connString]来读取配置文件。

在Windows Azure里,我们也可以将配置文件写入Web.config里。但是因为我们的Web App其实是Azure VM远程托管运行的,如果需要修改配置文件的话我们不得不远程登录桌面,然后再修改IIS下的Web.config文件。管理起来非常复杂。

所以在一般情况下,Windows Azure项目的配置文件是写到CSCFG文件里的

我们查看CSCFG可以看到

然后在Web Project的Global.asax文件,在Application_Start()函数里添加

 protected void Application_Start()        
{
  AreaRegistration.RegisterAllAreas();
  RegisterRoutes(RouteTable.Routes);
  CloudStorageAccount.SetConfigurationSettingPublisher((configName, configGetter) =>                
  {
  configGetter.Invoke(RoleEnvironment.GetConfigurationSettingValue(configName));
  });
}

这样在需要获取SQLCOnnectionString的时候调用:

CloudStorageAccount.FromConfigurationSetting("SQLConnectionString")

如果将来用户想修改CSCFG文件的时候,可以用过用户管理界面来修改

Windows Azure

 
 
posted @ 2012-03-02 17:30 Lei Zhang的博客 阅读(368) | 评论 (0) 编辑
 
posted @ 2012-02-06 18:06 Lei Zhang的博客 阅读(613) | 评论 (0) 编辑
 
posted @ 2012-01-30 17:16 Lei Zhang的博客 阅读(88) | 评论 (0) 编辑
 
posted @ 2012-01-30 15:48 Lei Zhang的博客 阅读(744) | 评论 (0) 编辑
 
posted @ 2012-01-23 00:08 Lei Zhang的博客 阅读(32) | 评论 (0) 编辑
 
posted @ 2012-01-22 12:53 Lei Zhang的博客 阅读(40) | 评论 (0) 编辑
 
posted @ 2012-01-22 12:44 Lei Zhang的博客 阅读(22) | 评论 (0) 编辑
 
posted @ 2012-01-21 20:15 Lei Zhang的博客 阅读(65) | 评论 (0) 编辑
 
posted @ 2012-01-20 16:40 Lei Zhang的博客 阅读(70) | 评论 (0) 编辑
 
posted @ 2012-01-19 22:24 Lei Zhang的博客 阅读(60) | 评论 (0) 编辑
 
posted @ 2012-01-19 18:16 Lei Zhang的博客 阅读(45) | 评论 (0) 编辑
 
posted @ 2012-01-19 12:28 Lei Zhang的博客 阅读(44) | 评论 (0) 编辑
 
posted @ 2012-01-18 18:30 Lei Zhang的博客 阅读(72) | 评论 (0) 编辑
 
posted @ 2012-01-18 16:58 Lei Zhang的博客 阅读(72) | 评论 (1) 编辑
 
posted @ 2012-01-18 16:33 Lei Zhang的博客 阅读(67) | 评论 (0) 编辑
 
posted @ 2012-01-18 14:47 Lei Zhang的博客 阅读(59) | 评论 (0) 编辑
 
posted @ 2012-01-17 19:38 Lei Zhang的博客 阅读(61) | 评论 (0) 编辑
 
posted @ 2012-01-17 15:03 Lei Zhang的博客 阅读(73) | 评论 (0) 编辑
 
posted @ 2012-01-17 12:57 Lei Zhang的博客 阅读(72) | 评论 (0) 编辑
 
posted @ 2012-01-17 11:26 Lei Zhang的博客 阅读(64) | 评论 (0) 编辑
 
posted @ 2012-01-16 19:32 Lei Zhang的博客 阅读(90) | 评论 (1) 编辑
 
posted @ 2012-01-16 18:41 Lei Zhang的博客 阅读(145) | 评论 (4) 编辑
 
原文地址:https://www.cnblogs.com/Leo_wl/p/2378750.html