最近我搜索了如何创建自定义主体,我得到了答案,但有一件事我不明白,我在堆栈溢出时找到了这个解决方案
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Security.Principal;
namespace workflow.Authorize
{
interface ICustomPrincipal : IPrincipal
{
int Id { get; set; }
string FirstName { get; set; }
string LastName { get; set; }
}
public class CustomPrincipal : ICustomPrincipal
{
public IIdentity Identity { get; private set; }
public bool IsInRole(string role) {
if(this.Roles.Contains(role))
return true;
else
return false;
}
public CustomPrincipal(string email)
{
this.Identity = new GenericIdentity(email);
}
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Roles { get; set; }
}
public class CustomPrincipalSerializeModel
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Roles { get; set; }
}
}
但我不明白的是为什么开发人员创建了 ICustomPrincipal 接口并强制 CustomPrincipal 继承它 为什么 CustomPrincipal 类不直接从 IPrincipal 接口继承