我在ServiceStack的新版本中返回自定义AutenticateResponse的问题。此代码在以前版本的ServiceStack中工作,但在升级之后,它不再按预期运行。在新版ServiceStack中返回自定义AuthenticateResponse的意外结果
的AuthenticateResponse
public class CustomAuthResponse : AuthenticateResponse
{
public List<CustomCompanyDTO> Companies { get; set; }
public List<string> Roles { get; set; }
public List<string> Permissions { get; set; }
public string DisplayName { get; set; }
public string Email { get; set; }
}
的服务
public class CurrentUserService : AppServiceBase
{
public object Any(CurrentUser cu)
{
CustomAuthResponse response = new CustomAuthResponse();
response.DisplayName = UserSession.DisplayName;
response.Email = UserSession.Email;
response.Companies = UserSession.Companies;
response.UserName = UserSession.UserName;
response.Roles = UserSession.Roles;
response.Permissions = UserSession.Permissions;
return response;
}
}
在v3中我可以调用CurrentUserService并预期返回的所有数据。在v4中,当我调用CurrentUserService时,没有任何自定义字段包含在响应中。
我可以解决此特定呼叫通过改变代码如下:按预期工作
public class CurrentUserService : AppServiceBase
{
public object Any(CurrentUser cu)
{
CustomAuthResponse response = new CustomAuthResponse();
var x = new
{
DisplayName = UserSession.DisplayName,
Email = UserSession.Email,
Companies = UserSession.Companies,
UserName = UserSession.UserName,
Roles = UserSession.Roles,
Permissions = UserSession.Permissions,
};
return x;
}
}
上面的代码。我当然可以改变我的代码以这种方式工作,我主要想知道改变了什么,因为我很好奇它是否会影响我在其他地方的代码。尝试从Authenticate调用我的自定义CredentialsAuthProvider返回ny CustomAuthResponse时,我看到相同的问题。