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 @ 2010-04-30 17:13  沉默杨  阅读(2996)  评论(9编辑  收藏  举报