最近将开发的系统升级到ASP.net2.0,大部分功能都正常,但遇到一个小问题,请各位研究了ASP.net2.0的高人赐教。
  系统的菜单是自己写的自定义控件,继承于System.Web.UI.WebControls.WebControl,重写了AddAttributesToRender和RenderContents方法。由于控件是从数据库读出菜单明细,所以在页面调用该控件之前使用了一个过渡效果,先呈现一个GIF动画,然后隐藏该动画层,显示菜单。过渡效果代码如下:    Response.Buffer = true;
    Response.Write("<div id='processdiv' align='center' style='font-size: 9pt;color: #002957;'>");
    Response.Write("<br>加载菜单<br>");
    Response.Write("<img src='pic/loading.gif' width='94' height='17' align='absmiddle'>");
    Response.Write("</div>");
    Response.Write("<script language=javascript>");
    Response.Write("var dots = 0;var dotmax = 10;");
    Response.Write("function StartShowWait(){processdiv.style.visibility = 'visible'; }");
    Response.Write("function HideWait(){processdiv.style.display = 'none';");
    Response.Write("window.clearInterval();}");
    Response.Write("StartShowWait();</script>");
    Response.Flush();  该功能在ASP.net1.1中使用正常,但升级到2.0后,每次访问菜单页面都会报错:异常详细信息: System.Web.HttpException: 会话状态已创建一个会话 ID,但由于响应已被应用程序刷新而无法保存它。堆栈跟踪:    [HttpException (0x80004005): 会话状态已创建一个会话 ID,但由于响应已被应用程序刷新而无法保存它。]
   System.Web.SessionState.SessionIDManager.SaveSessionID(HttpContext context, String id, Boolean& redirected, Boolean& cookieAdded) +2172127
   System.Web.SessionState.SessionStateModule.CreateSessionId() +55
   System.Web.SessionState.SessionStateModule.DelayedGetSessionId() +64
   System.Web.SessionState.SessionStateModule.OnReleaseState(Object source, EventArgs eventArgs) +328
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +92
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64  经查MSDN,发现HttpResponse.Flush 方法在发送了响应之后刷新缓存的情况下,会抛出HttpException异常,感觉和这个有关系,不知道是不是在2.0里面强化了某些机制……  这种情况该如何解决呢?多谢!