需要ServiceConfiguration.cscfg填充的web.config的sessionState和连接字符串 [英] Need ServiceConfiguration.cscfg to populate web.config sessionstate and connection strings

查看:256
本文介绍了需要ServiceConfiguration.cscfg填充的web.config的sessionState和连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要我的时候调整这些设置传播在web.config中的实体框架,asp.net成员连接字符串的变化(这两者都是在web.config中的connectionStrings节)和会话状态(这是sessonstate的sqlconnectionstring) Windows Azure中的服务配置。

I need to propagate connection string changes for entity framework, asp.net membership (which are both in the connectionstrings section of web.config) and session state (which is in sessonstate's sqlconnectionstring) in web.config when I adjust these settings in windows azure's service configuration.

在开发过程中,我们测试我们的应用程序作为一个标准的asp.net web表单应用程序,但一旦它部署在Azure中运行。因此,我们需要允许在两个非Azure和蔚蓝的上下文中运行该网站。这就是为什么我们只是在web.config中依赖于该值now.Since这些连接字符串不是在我的code直接调用写一个工具类,从蔚蓝的服务配置抓起,如果可用或以其他方式网站抓起的.config是不为这些值的可能性。

During development we test our app as a standard asp.net webforms app, but once it is deployed it is running in azure. So we need to allow for the site running in both non-azure and an azure context. That's why we're just relying upon the values in web.config for now.Since these connection strings are not called directly in my code writing a utility class which grabs from azure service config if that is available or otherwise grabs from web.config is not a possibility for these values.

我认识到,编辑web.config中会导致中断服务 - 我只打算在下班时间做到这一点。

I realize that editing web.config would cause a disruption in service - and i only plan to do this during off hours.

推荐答案

我认为最好的办法是换您的配置信息的服务。然后,在服务中,使用RoleEnvironment来确定要使用的设置。例如:

I believe that the best approach is to wrap your configuration information in a service. Then, in the service, use RoleEnvironment to determine which settings to use. For example

public static class Config
{
    public static string ConnStr
    {
        get
        {
            if (RoleEnvironment.IsAvailable)
                return RoleEnvironment.GetConfigurationSettingValue("ConnStr");

            return ConfigurationManager.AppSettings["ConnStr"];
        }
    }
}

如果不工作,你需要改变实际的web.config文件(例如,使用命名连接字符串),那么你就需要在运行时修改的配置。在你的角色开始,做类似以下内容:

If that doesn't work, and you need to change the actual web.config (for instance, using named connection strings), then you'll need to modify the config at runtime. In your role start, do something like the following:

var config = WebConfigurationManager.OpenWebConfiguration(null);
var connStrs = WebConfigurationManager.OpenWebConfiguration(null).GetSection("connectionStrings") as ConnectionStringsSection;
connStrs.ConnectionStrings["ConnStr"].ConnectionString = RoleEnvironment.GetConfigurationSettingValue("ConnStr");
config.Save();

要的作用后,配置更改运行时处理,只需拨打同一个code如上从RoleEnvironment.Changing事件。

To handle when the configuration changes after the role is running, just call the same code as above from the RoleEnvironment.Changing event.

祝你好运,

埃里克

这篇关于需要ServiceConfiguration.cscfg填充的web.config的sessionState和连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆