Reputation: 1513
I am trying to implement ASP.NET Identity 2.0. I have created a MVC4 project in VS 2012 and installed ASP.NET Identity 2.0 packages using Nu Get command. I am getting compile error message 'Microsoft.Owin.Security.AuthenticationManager' is inaccessible due to its protection level'with following code.
Getting compile error because AuthenticationManager is a internal class in assembly EntityFramework.dll. So can I derive a class from AuthenticationManager and call public methods SignIn() and SignOut().
There is a class AuthenticationManagerExtensions in same assembly. How can I use this for SignIn and 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);
}
Upvotes: 3
Views: 5851
Reputation: 1513
The AuthenticationManager used here is the Authentication object of the current Owin context. The problem is resolved by adding following property in same class.
private IAuthenticationManager AuthenticationManager
{
get
{
return HttpContext.GetOwinContext().Authentication;
}
}
Upvotes: 8