[英]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.