did you set Context.User to your LineWellPrincipal (for example, in global.asax or some HttpModule) before it reaches your page??if you didn't, what do you expect?

解决方案 »

  1.   

    我做了个基类,然后每个页面继承它
    这样就不需要在global.asax的Application_AuthenticateRequest()中写代码了public class LineWellPage : System.Web.UI.Page
    {
    public LineWellPage()
    {
    } protected override void OnInit(EventArgs e)
    {
    base.OnInit(e);
    this.Load += new System.EventHandler(this.LineWellPage_Load);

    }private void LineWellPage_Load(object sender, System.EventArgs e)
    {

    if (Context.User.Identity.IsAuthenticated) 
    {
    if (!(Context.User is LineWellPrincipal))
    {

    LineWellPrincipal newUser = new LineWellPrincipal( Context.User.Identity.Name );
    Context.User = newUser;
    }
    }
    }
    }
      

  2.   

    我把LineWellPage_Load()中的代码放到Application_AuthenticateRequest()里就好用了,但我搞不明白为什么这样, LineWellPage在每个页面load前调用,原理应该具有在cation_AuthenticateRequest()中一样的效果,是我理解错了还是有别的原因,saucer能否帮忙解释一下
      

  3.   

    不太明白,如果你是在Page_Load之后使用Context.User的话,结果应该是类似的,不过还是建议你在Application_AuthenticateRequest里建立关系,唯一有问题的地方是,你的编码里调用基类的Page_Load了么?