简体   繁体   English

如何以声明方式从 ServiceConfiguration.cscfg 读取应用程序设置?

[英]How can I declaratively read app settings from ServiceConfiguration.cscfg?

Web.Config Web.Config

<appSettings>
   <add key="minimumValue" value="0" />
   <add key="maximumValue" value="1000" />
</appSettings>

Web Form Web表格

<asp:RangeValidator ID="RangeValidator1" runat="server" Display="None" ErrorMessage="Error message." ControlToValidate="TextBox" MinimumValue="<%$ appSettings:minimumValue %>" MaximumValue="<%$ appSettings:maximumValue %>" Type="Integer" />

App settings in Web.config file are read-only after deployment process. Web.config 文件中的应用程序设置在部署过程后是只读的。 So I put these settings to ServiceDefinition.csdef and ServiceConfiguration.cscfg files and I can read them via code-behind:所以我将这些设置放到 ServiceDefinition.csdef 和 ServiceConfiguration.cscfg 文件中,我可以通过代码隐藏来读取它们:

RoleEnvironment.GetConfigurationSettingValue

Does it exists declarative way for this?它是否存在为此的声明方式?

Like <%$ appSettings:maximumValue %> for app setting in Web.Config.像 <%$ appSettings:maximumValue %> 用于 Web.Config 中的应用程序设置。

You can get it in this way:您可以通过以下方式获得它:

MinimumValue='<%# System.Configuration.ConfigurationManager.AppSettings["minimumValue"] %>'

And add this, as it will bind the value to your property:并添加这个,因为它会将值绑定到您的属性:

 protected void Page_PreRenderComplete(object sender, EventArgs e)
{
    DataBind();
}

For Details on how this works, check this thread: how-to-set-contol-property-in-asp-net有关其工作原理的详细信息,请查看此线程: how-to-set-contol-property-in-asp-net

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在ASP.NET中以声明方式使用附属程序集 - How can I consume satellite assemblies declaratively in ASP.NET 如何以编程方式为我的Azure Worker角色编辑ServiceConfiguration文件的NetworkConfiguration节点? - How can I Programatically edit the NetworkConfiguration node of the ServiceConfiguration file for my Azure Worker Roles? 如何从差异应用程序读取app.config中的用户设置? - How to read user settings in app.config from a diff app? 如何将我的应用程序设置保存到文本文件并在加载时重新读取? - How can i save settings of my app to a text file and read them back on load? 如何从web.config的system.net部分读取defaultProxy设置的值? - How can I read the values of the defaultProxy settings from the system.net section in a web.config? 如何在不使用每个应用程序将更新保存在其自己的文件夹中的情况下从一个公共程序集中共享一个公共用户配置(settings.settings)? - How can I share a common user config (settings.settings) from a common assembly without each app saving updates in their own folder? 如何从 C# 应用程序设置中读取 Json 对象 - How to read Json object from C# app settings 如何从.NET Core应用程序的其他层访问IOptions(或任何设置)? - How can I access IOptions (or any settings) from other tiers of my .NET Core app? 在 WPF 中,如何绑定到 app.config 中 configSections 中的设置? - In WPF how can I bind to settings in configSections in app.config? 无法从app.Config读取设置 - Unable to read settings from app.Config
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM