C# 根据主题改变形象

C# 根据主题改变形象,c#,asp.net,C#,Asp.net,在页面加载时,我正在添加此代码 if (Request.Cookies["switchstyle"] != null) { string i = Request.Cookies["switchstyle"].Value; if(i == "1") ThemeImageUrl = "~/ImagesW"; else ThemeImageUrl = "~/Images"; } 我正在写代码 CipCalendar.TodaysDate =

在页面加载时,我正在添加此代码

if (Request.Cookies["switchstyle"] != null)
{
    string  i = Request.Cookies["switchstyle"].Value;
    if(i == "1")
        ThemeImageUrl = "~/ImagesW";
    else
        ThemeImageUrl = "~/Images";
}
我正在写代码

CipCalendar.TodaysDate = CipCalendar.TodaysDate.AddMonths(-1);

StoreMonthValue(CipCalendar.TodaysDate.ToString()); // storing month in a cookie.
//Month.Text = CipCalendar.TodaysDate.ToString(MONTH_FORMAT);
imgMonth.ImageUrl = ThemeImageUrl + "/CalendarImages/" + CipCalendar.TodaysDate.ToString(MONTH_FORMAT) + ".gif";
SetMonthNavigateButtonVisible();
SetYearNavigateButtonVisible();
isNextMonth = false;
SetCases();
工作正常,图像上的日期正在更改,但当我使用浏览器返回btn时,此代码不起作用


根据我按下btnpriv时的主题变化以及浏览器后退btn日期应发生变化,而现在点击浏览器后退btn时不会发生这种变化,有2种方法认为您可以做到

首先更改主题,然后使用redirect()重新加载页面,用户无法返回。当使用“返回”从缓存中重新加载页面以查看上一个图像时,符合逻辑

其次,禁用动态页面的缓存

public static void DisablePageCaching() 
{ 
//Used for disabling page caching 
HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
HttpContext.Current.Response.Cache.SetValidUntilExpires(false); 
HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore(); 

} 

有两个理由认为你能做到

首先更改主题,然后使用redirect()重新加载页面,用户无法返回。当使用“返回”从缓存中重新加载页面以查看上一个图像时,符合逻辑

其次,禁用动态页面的缓存

public static void DisablePageCaching() 
{ 
//Used for disabling page caching 
HttpContext.Current.Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
HttpContext.Current.Response.Cache.SetValidUntilExpires(false); 
HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
HttpContext.Current.Response.Cache.SetNoStore(); 

} 

我正在使用两个主题黑白,背面主题1月、2月、3月黑色图像在那里,白色主题1月、2月、3月白色图像在那里,通过使用我的代码正在更改,但当我使用浏览器返回btn时,黑色主题1月、2月的一段时间后,三月白色图像即将到来,不能在黑色主题上显示,只能在黑色主题上显示黑色图像。白色主题不会出现这种情况。我应该在哪里调用DisablePageCaching(),我是在页面加载时调用它的。任何人都请帮助我解决这个问题。@Abuhurra页面加载时是加载它的好方法。第二种尝试是使用Response.Redirect,在用户更改响应后进行重定向。将他重定向到同一页-试试看。我没有得到确切的解决方案。我无法使用response.redirect,因为我正在Cookies的帮助下更改广播btn检查的主题我使用了两个黑白主题,在背面主题1月、2月、3月黑色图像在那里,在白色1月、2月、3月白色图像在那里,使用我的代码正在更改,但当我使用浏览器时,黑色主题1月、2月、3月白色图像在那里,2月,3月白色图像即将到来,不能在黑色主题上显示,只能在黑色主题上显示黑色图像。白色主题不会出现这种情况。我应该在哪里调用DisablePageCaching(),我是在页面加载时调用它的。任何人都请帮助我解决这个问题。@Abuhurra页面加载时是加载它的好方法。第二种尝试是使用Response.Redirect,在用户更改响应后进行重定向。将他重定向到同一页-试试看。我没有得到确切的解决方案。我无法使用response.redirect,因为我正在借助cookies更改广播btn检查的主题