如何在 ASP.NET Identity 中扩展 ApplicationUser 但属性可以为空?
How can I extend ApplicationUser in ASP.NET Identity but with properties that can be null?
我想扩展应用程序用户。这是一个例子:
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity>
GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
return userIdentity;
}
public string Address { get; set; }
public string City { get; set; }
public string State { get; set; }
我试过了,但是当我登录时,如果这些属性中的任何一个在数据库中设置为 null,那么在进行 /Token 调用时似乎 returns 出现错误。
谁能告诉我。我是否需要更改这些属性在此处或其他位置的设置方式?
如果我正确理解你的问题,一个简单的解决方案就是创建一个 nullable type。你能分享一下你想做什么吗?例如,创建自定义身份提供程序?
我想扩展应用程序用户。这是一个例子:
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity>
GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
return userIdentity;
}
public string Address { get; set; }
public string City { get; set; }
public string State { get; set; }
我试过了,但是当我登录时,如果这些属性中的任何一个在数据库中设置为 null,那么在进行 /Token 调用时似乎 returns 出现错误。
谁能告诉我。我是否需要更改这些属性在此处或其他位置的设置方式?
如果我正确理解你的问题,一个简单的解决方案就是创建一个 nullable type。你能分享一下你想做什么吗?例如,创建自定义身份提供程序?