已知LineWellPrincipal是一个IPricipal的扩展基类,强制转换出错 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? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我做了个基类,然后每个页面继承它这样就不需要在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; } } }} 我把LineWellPage_Load()中的代码放到Application_AuthenticateRequest()里就好用了,但我搞不明白为什么这样, LineWellPage在每个页面load前调用,原理应该具有在cation_AuthenticateRequest()中一样的效果,是我理解错了还是有别的原因,saucer能否帮忙解释一下 不太明白,如果你是在Page_Load之后使用Context.User的话,结果应该是类似的,不过还是建议你在Application_AuthenticateRequest里建立关系,唯一有问题的地方是,你的编码里调用基类的Page_Load了么? 使用session时出错 ASP.NET 请教一个类设计的问题(只有70分了,不好意思) 页面级访问,级联更新 急问:关于owc11画图及多用户浏览的问题,用过owc的就进来看看吧 Treeview问题 页面框架的问题 请大家帮忙,刚开始学习ASP.NET碰到的问题 求国外paypal的IPN支付范例,看英文看的头晕,有用的给10分先,另外开贴送100! 怎样转换如下的vb.net代码到C# 如何将回车提交表单事件绑定到textbox控件? 标准模块中如何调用application对象
这样就不需要在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;
}
}
}
}