开发者

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

开发者 https://www.devze.com 2023-03-08 09:37 出处:网络
Web.Config <appSettings> <add key=\"minimumValue\" value=\"0\" /> <add key=\"maximumValue\" value=\"1000\" />

Web.Config

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

Web Form

<asp:RangeValidator ID="RangeValidator1" runat="server" Display="None" ErrorMessage="Error message." Co开发者_如何学GontrolToValidate="TextBox" MinimumValue="<%$ appSettings:minimumValue %>" MaximumValue="<%$ appSettings:maximumValue %>" Type="Integer" />

App settings in Web.config file are read-only after deployment process. So I put these settings to ServiceDefinition.csdef and ServiceConfiguration.cscfg files and I can read them via code-behind:

RoleEnvironment.GetConfigurationSettingValue

Does it exists declarative way for this?

Like <%$ appSettings:maximumValue %> for app setting in 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

0

精彩评论

暂无评论...
验证码 换一张
取 消