"I'm getting an error when calling an API in CSLA: 'The principal must be of type BusinessPrincipal, cannot be Nothing'. However, I have already marked the user identity. #4206
-
"I'm getting an error when calling an API in CSLA: 'The principal must be of type BusinessPrincipal, cannot be Nothing'. However, I have already marked the user identity. Here's the code: [Code snippet]" private async void button4_Click(object sender, EventArgs e)
{
var claims = new Claim[]
{
new Claim(ClaimTypes.Name, "Test User"),
new Claim(ClaimTypes.Role, "Admin"),
};
var identity = new ClaimsIdentity(claims, "Test", ClaimTypes.Name, ClaimTypes.Role);
Program.ApplicationContext.User = new ClaimsPrincipal(identity);
var DataPortal = Program.ApplicationContext.GetRequiredService<IDataPortal<PersonEdit>>();
try
{
var PersonEdit = await DataPortal.FetchAsync(25);
this.textBox1.Text = System.Text.Json.JsonSerializer.Serialize(PersonEdit);
}
catch (Exception rc)
{
this.textBox1.Text = rc.Message;
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
The data portal requires that the client and server be configured the same - either to pass the principal or not. How you do this depends on the version of CSLA. In CSLA 8 it is like this (in your services.AddCsla(o => o
.Security(sec => sec.FlowSecurityPrincipalFromClient = false)); That assumes that you do not want the principal to flow from client to server. You can set both client and server to The default is |
Beta Was this translation helpful? Give feedback.
-
TKS Rockford Lhotka, I set up the server, but not the client. The issue has been resolved. |
Beta Was this translation helpful? Give feedback.
The data portal requires that the client and server be configured the same - either to pass the principal or not.
How you do this depends on the version of CSLA.
In CSLA 8 it is like this (in your
Program.cs
files on client and server):That assumes that you do not want the principal to flow from client to server. You can set both client and server to
true
if you do want the client principal to flow to the server via the data portal.The default is
false
.