ASPX页面基于条件设置图片URL的部署异常问题咨询
问题:ASPX页面图片加载逻辑服务器端延迟生效
本地运行完全正常,但部署到服务器后,即便IsEnabled值设为true,仍会加载isfalse.gif,数天后才会根据IsEnabled值加载正确图片。
相关代码
后台IsEnabled属性
protected bool IsEnabled { get { return Utility.GetValue("TestKey"); } }
Utility类伪代码
public static class Utility { public static bool GetValue(string keyName) { bool kvalue = false; // string value = string.Empty; //以下缓存为全局级,下方仅为数据存在形式的伪代码 Dictionary<string, string> dicCacheDictionary = new Dictionary<string, string>(); if (dicCacheDictionary.TryGetValue(keyName, out string value)) { if (bool.TryParse(value, out bool result)) return result; } else { //从数据库获取并添加到缓存 //当前仅为伪代码,硬编码值 dicCacheDictionary.Add(keyName, "true"); } //若缓存中无数据则从数据库获取 return kvalue; } }
ASPX页面代码
<asp:Image ID="imgWebcast" ImageUrl='<%#(IsEnabled) ? "../../images/istrue.gif" : "../../images/isfalse.gif" %>' />
已排查事项
- 部署前已删除预编译文件缓存
- 已清除缓存
- 已重置IIS
我可通过后台代码设置轻松解决该问题,但想确认上述实现方式是否有效,是否存在错误,能否通过该方式实现需求。
内容的提问来源于stack exchange,提问作者Malcolm
相关产品推荐
相关产品推荐

