vs2010的bug

 准确的说,我不知道这是不是算vs2010一个bug,因为我对.net的运行机制也没啥太多的研究,基本上全靠自学,这个问题困扰了我两天,所有的方法都试遍了,还找了园子里面几个朋友帮忙,描述如下:

aspx页面继承adminpage.

复制代码
代码
public partial class post_categories :AdminPage
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
rptList.DataSource
= Post.Getcategories(0);
rptList.DataBind();
}
}
}
复制代码

 

 

 

adminpage页面

复制代码
代码
public class AdminPage:System.Web.UI.Page
{
protected override void OnInit(EventArgs e)
{
if (!StatusObject.CheckCookie("user"))
{
WebHint.PageError(
"非法访问,你还没有登录" "../admin_login.aspx");

}
base.OnInit(e);
}
}
复制代码

 

 

 

原意就是在adminpage类中判断cookie是否存在。不存在则返回到登录页面,就是这段代码导致了aspx页面所有的web控件全部无法显示。全部提示:

error creating error-控件id
Object reference set to an instance of an object

最终在msdn找到了答案,将判断cookie的这段代码先行注释了,恢复了正常,描述如下:

We are seeing this error because at the design time, some objects such as Session, are not available, or being null. However, the project still runs perfectly at runtime.

To workaround the issue, you can add code to check for the existence of the Session object as shown below, then the design view will render correctly.
We are considering adding a fix for this issue during the VS 2010 SP1 timeframe.
详见:http://blogs.msdn.com/webdevtools/archive/2010/04/15/rendering-issue-in-visual-studio-2010-when-accessing-the-session-state-in-the-oninit-method.aspx


  困扰了两天的问题解决,心里面真是一块石头落地,文章很初级,如果管理员觉得不合适,可以撤下首页。
  顺祝:“五一节快乐”

posted @   沉默杨  阅读(3003)  评论(9编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述
点击右上角即可分享
微信分享提示