一般在C#中造成“未将对象引用设置到对象的实例”错误都是控件名称与codebehind里面的没有对应像这里的问题的话,最好把你怎么定义JobPrincipal贴出来

解决方案 »

  1.   

    奇怪,看不出来
    这错误通常都是没有对一个对象进行 new
    可你的对象 new 了呀
      

  2.   

    肯定是JobPrincipal的定义有问题,建议贴出来分析
      

  3.   

    要实例化
    yourclass myclass = new youclass();
      

  4.   

    应该是JobPrincipal 定义有问题
      

  5.   

    我也不知道什么原因, 我把下面的代码放到Page_Load中就没事了,
    没有放到Global.asax.cs的Application_AuthenticateRequest。
     if(Context.User.Identity.IsAuthenticated) 
          {
          if(!(Context.User is JobPrincipal))
            {

    JobPrincipal newUser = new JobPrincipal( Context.User.Identity.Name );
    Context.User = newUser;
    }
           }
    还有个重要的问题就是我昨天晚上
    FormsAuthentication.SetAuthCookie( uname.Text, true );
    今天起来
    Context.User.Identity.IsAuthenticated的值是true
    Context.User.Identity.Name的值是uname.Text,??怪了