何时调用方法 SignIn 我收到错误 NullReferenceExepction。
这是我的视图模型:
public Masterpage1ViewModel() {
UserIdentity user = new UserIdentity("Admin");
var claimsIdentity = new ClaimsIdentity(user);
Context.OwinContext.Authentication.SignIn(claimsIdentity);
}
这是 UserIdentity 的类:
public class UserIdentity : IIdentity
{
public string AuthenticationType
{
get { return DefaultAuthenticationTypes.ApplicationCookie; }
}
public bool IsAuthenticated { get; set; }
public string Name { get; private set; }
public UserIdentity(string name)
{
Name = name;
}
}
我还添加到 Startup.cs:
app.UseCookieAuthentication(new CookieAuthenticationOptions()
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
Provider = new CookieAuthenticationProvider()
{
OnApplyRedirect = e => DotvvmAuthenticationHelper.ApplyRedirectResponse(e.OwinContext, e.RedirectUri)
}
});