Reputation: 2086
I've got a line like this in my Blazor Web Assembly app:
<Calendar User="@context.User.Claims.Where(user => user.Type == "sid")"></Calendar>
But VS doesn't like the fact that "sid" is in quotes because it messes up the User="" attribute. How do I handle this?
Also, side question, is this the proper way to get a user Id in blazor web assembly? This seems like the easiest way, but I'm new to authentication so I don't know if I'm violating a best practice by doing this.
Thanks!
Upvotes: 9
Views: 4495
Reputation: 10765
Use parenthesis between the @ and the C# code:
<Calendar User="@(context.User.Claims.Where(user => user.Type == "sid"))"></Calendar>
As to your second question, assuming you are using Asp.Net for your back end code, you can get the User object from the HttpContext.Current.User
of the user request server side, you can read more about this here (https://learn.microsoft.com/en-us/dotnet/api/system.security.claims.claimsprincipal?view=netcore-3.1)
Upvotes: 17
Reputation: 883
You can use parenthesis @( )
to make it a code block
<Calendar User="@(context.User.Claims.Where(user => user.Type == "sid"))" />
Upvotes: 6