我在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時,我看到相同的問題。