【发布时间】:2016-09-09 00:08:03
【问题描述】:
当调用方法 SignIn 时出现错误 NullReferenceExepction。
这是我的 ViewModel:
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)
}
});
【问题讨论】: