c# - Entity Framework 在母版页上找不到 "User"?

标签 c# .net webforms asp.net-identity

所以我按照本教程在 .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/

相关文章:

.net - 如何使用相同的代码从 DataRow 或 DataReader 读取数据?

javascript - "Gmail style"Web表单的部分更新

c# - 结构 C# 的大小

c# - 为什么循环 Array.AsSpan() 更快?

c# - 无论图像颜色如何,在图像上绘制可见文本

.net - 共享 IIS 服务器上的 HTTPS - 浏览器警告

.net - 使用MVVM和WPF显示项目的一致值

asp.net - 将生成的行和列添加到 aspx 文件中的表中

asp.net - cookie 是否具有相当于主键的功能?

c# - StackExchange.Redis.RedisTimeoutException : The timeout was reached before the message could be written to the output buffer, 并且未发送