所以我按照本教程在 .net 中安装和使用身份框架。 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...
}
并将它放在母版页的 Page_Load 中(这样我就可以显示登录或注销链接,具体取决于)
但是当我这样做的时候,我得到一个错误信息
The name 'User' does not exist in the current context
我在母版页后面的代码中有以下“使用”,这里的所有内容都在找到“用户”的 login.aspx 页面上。
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;
我有点懵!您如何在母版页上使用身份框架?实际上,我最终希望将登录表单集成到母版页本身,所以这可能会给我带来麻烦!
感谢任何帮助,只是刚刚发现了 Indentity Framework,所以请保持温柔 :)
最佳答案
尝试查看 HttpContext.Current.User
是否可访问。
关于c# - Entity Framework 在母版页上找不到 "User"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25720513/