Rese
Rese
CC#
Created by Rese on 4/29/2024 in #help
Blazor WSAM with Cognito Hosted UI issues
Hey there, I'm slightly struggling with getting Blazor WebAssembly to work with Cognito. I created a user pool, but I'm not exactly sure how it's supposed to work with Blazor. I was following this sample repo: https://github.com/sravimohan/blazor-webassembly-cognito-hosted-ui-sample/tree/main But it seems to not work, first and foremost the RemoteAuthenticatorView gives:
Refused to display 'https://***.auth.eu-central-1.amazoncognito.com/' in a frame because it set 'X-Frame-Options' to 'deny'.
Refused to display 'https://***.auth.eu-central-1.amazoncognito.com/' in a frame because it set 'X-Frame-Options' to 'deny'.
but then it redirects me to their actual UI, where if I try to log in, I come back with login failed to my website. I'd love to not bother you guys with this, but I'm not even sure how this thing is supposed to work (I come from Blazor Server).
8 replies
CC#
Created by Rese on 11/17/2023 in #help
SignalR initial connection takes way too long (logs included in comments)
Hey there. So I have two versions of the same application, using essentially the same code. One of them, however, has SignalR take around 10 seconds to make a connection to the hub, meanwhile the other ones takes like 2 seconds tops. Why could that be? Providing the code for connecting below:
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
_hubConnection = _hubService.MakeHubConnection(Constants.HubRoutes.DISPLAY_HUB);

_hubConnection.On<Settings>(Constants.HubRoutes.SETTINGS_UPDATED, async (settings) =>
{
_actionInProgress = true;
await InvokeAsync(StateHasChanged);

_settings = settings;

if (_settings.DefaultBackgroundId is not null)
{
using var db = _dbContextFactory.CreateDbContext();
_settings.DefaultBackground = await db.Images.FirstOrDefaultAsync(x => x.Id.Equals(_settings.DefaultBackgroundId));
}

_actionInProgress = false;
await InvokeAsync(StateHasChanged);
});

_hubConnection.On<Guid, string?, int>(Constants.HubRoutes.NOW_PLAYING_CHANGED, async (instance, _, _) =>
{
if (instance.Equals(_instance) || _queue is null)
return;

_actionInProgress = true;
await InvokeAsync(StateHasChanged);

using var db = _dbContextFactory.CreateDbContext();
await db.ReloadQueue(_queue);

_actionInProgress = false;
await InvokeAsync(StateHasChanged);
});

_ = TrackConnectionAsync(_hubConnection);
}
}

private async Task TrackConnectionAsync(HubConnection hubConnection)
{
await hubConnection.StartAsync();
_isConnected = true;
StateHasChanged();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
_hubConnection = _hubService.MakeHubConnection(Constants.HubRoutes.DISPLAY_HUB);

_hubConnection.On<Settings>(Constants.HubRoutes.SETTINGS_UPDATED, async (settings) =>
{
_actionInProgress = true;
await InvokeAsync(StateHasChanged);

_settings = settings;

if (_settings.DefaultBackgroundId is not null)
{
using var db = _dbContextFactory.CreateDbContext();
_settings.DefaultBackground = await db.Images.FirstOrDefaultAsync(x => x.Id.Equals(_settings.DefaultBackgroundId));
}

_actionInProgress = false;
await InvokeAsync(StateHasChanged);
});

_hubConnection.On<Guid, string?, int>(Constants.HubRoutes.NOW_PLAYING_CHANGED, async (instance, _, _) =>
{
if (instance.Equals(_instance) || _queue is null)
return;

_actionInProgress = true;
await InvokeAsync(StateHasChanged);

using var db = _dbContextFactory.CreateDbContext();
await db.ReloadQueue(_queue);

_actionInProgress = false;
await InvokeAsync(StateHasChanged);
});

_ = TrackConnectionAsync(_hubConnection);
}
}

private async Task TrackConnectionAsync(HubConnection hubConnection)
{
await hubConnection.StartAsync();
_isConnected = true;
StateHasChanged();
}
14 replies
CC#
Created by Rese on 9/10/2023 in #help
❔ EF Core DistinctBy alternative
Hey guys, is there like no way to use a DistinctBy alternative with EF Core? I tried this:
public static IQueryable<TSource> DistinctByDb<TSource, TKey>(
this IQueryable<TSource> source,
Expression<Func<TSource, TKey>> keySelector
) => source.GroupBy(keySelector).Select(x => x.First());
public static IQueryable<TSource> DistinctByDb<TSource, TKey>(
this IQueryable<TSource> source,
Expression<Func<TSource, TKey>> keySelector
) => source.GroupBy(keySelector).Select(x => x.First());
But this throws an error:
using var db = _dbContextFactory.CreateDbContext();
_mostCommonVehicles = await db.Vehicles.DistinctByDb(x => x.Name).Take(3).AsNoTracking().ToListAsync();
using var db = _dbContextFactory.CreateDbContext();
_mostCommonVehicles = await db.Vehicles.DistinctByDb(x => x.Name).Take(3).AsNoTracking().ToListAsync();
System.AggregateException: One or more errors occurred. (The LINQ expression 'ROW_NUMBER() OVER(PARTITION BY v0.Name ORDER BY v0.Id ASC)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.)
System.AggregateException: One or more errors occurred. (The LINQ expression 'ROW_NUMBER() OVER(PARTITION BY v0.Name ORDER BY v0.Id ASC)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.)
36 replies
CC#
Created by Rese on 8/25/2023 in #help
❔ How can I make a function of a simple condition EF Core translatable
Hey, so I have this function, but it seems to throw an error by not being translatable by EF Core, even though if the code is extracted from the function, it seems to work just fine. Function that cannot be translated:
public static bool IsWithinRange(this DateTime target, DateTime rangeStart, DateTime rangeEnd)
=> target >= rangeStart && target <= rangeEnd;
public static bool IsWithinRange(this DateTime target, DateTime rangeStart, DateTime rangeEnd)
=> target >= rangeStart && target <= rangeEnd;
But this is fine:
.Where(x => x.Timestamp >= _startDate && x.Timestamp <= _endDate)
.Where(x => x.Timestamp >= _startDate && x.Timestamp <= _endDate)
Can anyone explain how I can fix that?
25 replies
CC#
Created by Rese on 8/16/2023 in #help
❔ EF Core: Owned property with converter expression cannot be converted
21 replies
CC#
Created by Rese on 1/3/2023 in #help
❔ Identity - Stop automatic signing out
Hey, I'm using Identity with the remember me variable for keeping my users signed in, but when different people access the same account from different browsers, the previously signed in person gets logged out. Is there any way of preventing this?
3 replies
CC#
Created by Rese on 12/29/2022 in #help
❔ Custom validation attribute not displaying validation message
I'll butt in with a bit of a question. I'm using an EditForm in Blazor Server, where I directly pass it the EditContext and manually trigger the validation logic. Got a bit of an issue where if I validate something using a CustomAttribute, the validation result will blink for a bit in the validation message and then disappear. It's still there if I use a ValidationSummary, but not in the Validation Message for the specific field. Anyone got any idea why? form:
<EditForm EditContext="_merchantContext" class="create-link-form">
<DataAnnotationsValidator />

<div class="form-control">
<Name For="() => _merchant.EmailAddress" />
<InputText type="text" @bind-Value="_merchant.EmailAddress" placeholder="[email protected]"/>
<ValidationMessage For="() => _merchant.EmailAddress" />
</div>

<div class="form-control">
<Name For="() => _merchant.Iban" />
<InputText class="uppercase" type="text" @bind-Value="_merchant.Iban" placeholder="SKXX XXXX XXXX XXXX XXXX XXXX" />
<ValidationMessage For="() => _merchant.Iban" />
</div>
</EditForm>
<EditForm EditContext="_merchantContext" class="create-link-form">
<DataAnnotationsValidator />

<div class="form-control">
<Name For="() => _merchant.EmailAddress" />
<InputText type="text" @bind-Value="_merchant.EmailAddress" placeholder="[email protected]"/>
<ValidationMessage For="() => _merchant.EmailAddress" />
</div>

<div class="form-control">
<Name For="() => _merchant.Iban" />
<InputText class="uppercase" type="text" @bind-Value="_merchant.Iban" placeholder="SKXX XXXX XXXX XXXX XXXX XXXX" />
<ValidationMessage For="() => _merchant.Iban" />
</div>
</EditForm>
Validate call:
private void SubmitPart(EditContext context) {
var result = context.Validate();

if(!result) {
_isSubmitting = false;
return;
}

GoTo(_currentPage+1);
}
private void SubmitPart(EditContext context) {
var result = context.Validate();

if(!result) {
_isSubmitting = false;
return;
}

GoTo(_currentPage+1);
}
2 replies
CC#
Created by Rese on 9/10/2022 in #help
Is there a way to catch Blazor's StateHasChanged as an en event in JS?
As the title states. I need to execute some JS code after page is updated.
1 replies