我正在尝试实现ASP.NET Identity 2.0.我在VS 2012中创建了一个MVC4项目,并使用Nu Get命令安装了ASP.NET Identity 2.0软件包.我收到编译错误消息"Microsoft.Owin.Security.AuthenticationManager"由于其保护级别而无法访问,具有以下代码.
获取编译错误,因为AuthenticationManager是程序集EntityFramework.dll中的内部类.因此,我可以从AuthenticationManager派生一个类并调用公共方法SignIn()和SignOut().
在同一个程序集中有一个AuthenticationManagerExtensions类.我怎样才能将它用于SignIn和SignOut?
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);
}
Run Code Online (Sandbox Code Playgroud)