Identity Framework无法在主页面上找到"用户"?

Stu*_*art 3 .net c# webforms asp.net-identity

所以我按照本教程在.net中安装和使用Identity Framework. http://www.asp.net/identity/overview/getting-started/adding-aspnet-identity-to-an-empty-or-existing-web-forms-project

在register.aspx和login.aspx页面上一切正常.

我想从登录页面中获取这个逻辑......

if (User.Identity.IsAuthenticated) {
    //do something...
}
Run Code Online (Sandbox Code Playgroud)

并将其放在母版页的Page_Load中(因此我可以显示登录或注销链接,具体取决于)

但是,当我这样做时,我收到一个错误

"User"这个名称在当前上下文中不存在

我在主页面上的代码中有以下'使用',这里的所有内容都在login.aspx页面上,其中找到了'User'.

using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using Microsoft.Owin.Security;
using SugarSpun_v2;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
Run Code Online (Sandbox Code Playgroud)

我有点困惑!您如何在母版页上使用Identity Framework?我实际上最终希望将登录表单集成到母版页本身上,所以这可能会导致我出现问题!

任何帮助赞赏,只是发现了Indentity Framework,所以请温柔:)

Kip*_*pie 5

试着看看是否HttpContext.Current.User可以访问.