gpt4 book ai didi

asp.net-identity - Microsoft.Owin.Security.AuthenticationManager' 由于其保护级别而无法访问

转载 作者:行者123 更新时间:2023-12-02 02:36:51 25 4
gpt4 key购买 nike

我正在尝试实现 ASP.NET Identity 2.0。我在 VS 2012 中创建了一个 MVC4 项目,并使用 Nu Get 命令安装了 ASP.NET Identity 2.0 包。我收到编译错误消息“Microsoft.Owin.Security.AuthenticationManager”由于其保护级别而无法访问,代码如下。

出现编译错误,因为 AuthenticationManager 是程序集 EntityFramework.dll 中的内部类。那么我可以从 AuthenticationManager 派生一个类并调用公共(public)方法 SignIn() 和 SignOut() 吗?

同一程序集中有一个 AuthenticationManagerExtensions 类。我如何使用它进行登录和退出?

using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using System.Threading.Tasks;
using Microsoft.Owin.Security;

private async Task SignInAsync(ApplicationUser user, bool isPersistent)
{
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);

var identity = await UserManager.CreateIdentityAsync(
user, DefaultAuthenticationTypes.ApplicationCookie);

AuthenticationManager.SignIn(
new AuthenticationProperties()
{
IsPersistent = isPersistent
}, identity);
}

最佳答案

这里使用的AuthenticationManager是当前Owin上下文的Authentication对象。通过在同一类中添加以下属性解决了该问题。

    private IAuthenticationManager AuthenticationManager
{
get
{
return HttpContext.GetOwinContext().Authentication;
}
}

关于asp.net-identity - Microsoft.Owin.Security.AuthenticationManager' 由于其保护级别而无法访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22929626/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com