IcyIme
IcyIme
CC#
Created by IcyIme on 7/29/2024 in #help
how can i run multiple projects in vscode
No description
4 replies
CC#
Created by IcyIme on 7/17/2024 in #help
✅ i want get the id of user but id wont show up of user blazor wasm with web api
there is git repo: https://github.com/IcyIme/UniCademyProject page name: Userid.razor
17 replies
CC#
Created by IcyIme on 7/16/2024 in #help
✅ ClaimTypes.NameIdentifier not retruning id of current user
i want to get id of current user but ClaimTypes.NameIdentifier not working and i dont know why
@page "/profile"
@using System.Security.Claims
@using Microsoft.AspNetCore.Authorization
@using UniCademy.Client.Model
@inject AuthenticationStateProvider AuthenticationStateProvider
@attribute [Authorize]

<PageTitle>Profile</PageTitle>

<h1>@name</h1>
<h2>@userId</h2>

@code {
private string name;
private string userId;

protected override async Task OnInitializedAsync()
{
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var user = authState.User;

if (user.Identity.IsAuthenticated)
{
name = user.Identity.Name;
userId = user.FindFirst(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
}
else
{
name = "User not authenticated";
userId = "No ID";
}
}
}
@page "/profile"
@using System.Security.Claims
@using Microsoft.AspNetCore.Authorization
@using UniCademy.Client.Model
@inject AuthenticationStateProvider AuthenticationStateProvider
@attribute [Authorize]

<PageTitle>Profile</PageTitle>

<h1>@name</h1>
<h2>@userId</h2>

@code {
private string name;
private string userId;

protected override async Task OnInitializedAsync()
{
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var user = authState.User;

if (user.Identity.IsAuthenticated)
{
name = user.Identity.Name;
userId = user.FindFirst(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
}
else
{
name = "User not authenticated";
userId = "No ID";
}
}
}
22 replies
CC#
Created by IcyIme on 7/15/2024 in #help
identity blazor
i have this code for getting user id of current user but its return null
csharp protected override async Task OnParametersSetAsync()
{
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var user = authState.User;

if (string.IsNullOrEmpty(userId) && user.Identity.IsAuthenticated)
{
var userIdClaim = user.FindFirst(c => c.Type == "sub");
userId = userIdClaim?.Value;
}

await LoadProfileData();
}
csharp protected override async Task OnParametersSetAsync()
{
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
var user = authState.User;

if (string.IsNullOrEmpty(userId) && user.Identity.IsAuthenticated)
{
var userIdClaim = user.FindFirst(c => c.Type == "sub");
userId = userIdClaim?.Value;
}

await LoadProfileData();
}
i use blazor wasm and web api
4 replies
CC#
Created by IcyIme on 7/14/2024 in #help
✅ asp.net web api connection refused
No description
1 replies
CC#
Created by IcyIme on 7/7/2024 in #help
✅ A second operation was started on this context instance before a previous operation completed.
i have two layoust one for mobile and second for pc and when i use mobile layout it throws me this error
System.InvalidOperationException: A second operation was started on this context instance before a previous operation completed. This is usually caused by different threads concurrently using the same instance of DbContext. For more information on how to avoid threading issues with DbContext, see https://go.microsoft.com/fwlink/?linkid=2097913.
at Microsoft.EntityFrameworkCore.Infrastructure.Internal.ConcurrencyDetector.EnterCriticalSection()
at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at GradeProject.Components.Pages.ProfilePage.GetLeaderboardPositionAsync(Int32 score) in c:\Users\peter\Desktop\Grade\GradeProject\GradeProject\Components\Pages\ProfilePage.razor:line 143
at GradeProject.Components.Pages.ProfilePage.OnInitializedAsync() in c:\Users\peter\Desktop\Grade\GradeProject\GradeProject\Components\Pages\ProfilePage.razor:line 135
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()

System.InvalidOperationException: A second operation was started on this context instance before a previous operation completed. This is usually caused by different threads concurrently using the same instance of DbContext. For more information on how to avoid threading issues with DbContext, see https://go.microsoft.com/fwlink/?linkid=2097913.
at Microsoft.EntityFrameworkCore.Infrastructure.Internal.ConcurrencyDetector.EnterCriticalSection()
at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at GradeProject.Components.Pages.ProfilePage.GetLeaderboardPositionAsync(Int32 score) in c:\Users\peter\Desktop\Grade\GradeProject\GradeProject\Components\Pages\ProfilePage.razor:line 143
at GradeProject.Components.Pages.ProfilePage.OnInitializedAsync() in c:\Users\peter\Desktop\Grade\GradeProject\GradeProject\Components\Pages\ProfilePage.razor:line 135
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()

csharp @using GradeProject.Components.Account.Shared

<MediaQueryList>
<ViewTransitionRouter AppAssembly="typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="routeData" DefaultLayout="@(isMobile ? typeof(Layout.MobileLayout) : typeof(Layout.MainLayout))">
<NotAuthorized>
<RedirectToLogin/>
</NotAuthorized>
</AuthorizeRouteView>
<FocusOnNavigate RouteData="routeData" Selector="[autofocus]"/>
</Found>
</ViewTransitionRouter>
<MediaQuery Media="(max-width: 600px)" @bind-Matches="isMobile" />
</MediaQueryList>

@code {
private bool isMobile;
}
csharp @using GradeProject.Components.Account.Shared

<MediaQueryList>
<ViewTransitionRouter AppAssembly="typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="routeData" DefaultLayout="@(isMobile ? typeof(Layout.MobileLayout) : typeof(Layout.MainLayout))">
<NotAuthorized>
<RedirectToLogin/>
</NotAuthorized>
</AuthorizeRouteView>
<FocusOnNavigate RouteData="routeData" Selector="[autofocus]"/>
</Found>
</ViewTransitionRouter>
<MediaQuery Media="(max-width: 600px)" @bind-Matches="isMobile" />
</MediaQueryList>

@code {
private bool isMobile;
}
5 replies
CC#
Created by IcyIme on 6/26/2024 in #help
i want to migrate db from sqlserver to supabase(postressql) but i have error with entitity framework
i want to migrate db from sqlserver to supabase(postressql) but i have error with entitity framework
SELECT EXISTS (
SELECT 1 FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace
WHERE n.nspname='public' AND
c.relname='__EFMigrationsHistory'
)
Npgsql.NpgsqlException (0x80004005): Exception while reading from stream
---> System.TimeoutException: Timeout during reading attempt
at Npgsql.Internal.NpgsqlReadBuffer.<Ensure>g__EnsureLong|55_0(NpgsqlReadBuffer buffer, Int32 count, Boolean async, Boolean readingNotifications)
at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at Npgsql.Internal.NpgsqlConnector.ReadMessageLong(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)
at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
at Npgsql.NpgsqlDataReader.NextResult()

Exception while reading from stream
SELECT EXISTS (
SELECT 1 FROM pg_catalog.pg_class c
JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace
WHERE n.nspname='public' AND
c.relname='__EFMigrationsHistory'
)
Npgsql.NpgsqlException (0x80004005): Exception while reading from stream
---> System.TimeoutException: Timeout during reading attempt
at Npgsql.Internal.NpgsqlReadBuffer.<Ensure>g__EnsureLong|55_0(NpgsqlReadBuffer buffer, Int32 count, Boolean async, Boolean readingNotifications)
at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
at Npgsql.Internal.NpgsqlConnector.ReadMessageLong(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)
at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
at Npgsql.NpgsqlDataReader.NextResult()

Exception while reading from stream
3 replies
CC#
Created by IcyIme on 6/23/2024 in #help
i migrating from sqlserver to mongo db but in login the page throeing an errror ExpressionNotSupport
No description
16 replies
CC#
Created by IcyIme on 3/23/2024 in #help
I want to make a dynamic compiler of c# code and with that have a console on the web page, using thi
I want to make a dynamic compiler of c# code and with that have a console on the web page, using this it will be possible to interact with the code
14 replies
CC#
Created by IcyIme on 1/25/2024 in #help
i have problem with ef core in rider
/usr/lib/dotnet/dotnet ef database update --project TeamManager/TeamManager.csproj --startup-project TeamManager/TeamManager.csproj --context TeamManager.Data.ApplicationDbContext --configuration Debug 20240124212353_azure
Could not execute because the specified command or file was not found.
Possible reasons for this include:
* You misspelled a built-in dotnet command.
* You intended to execute a .NET program, but dotnet-ef does not exist.
* You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
/usr/lib/dotnet/dotnet ef database update --project TeamManager/TeamManager.csproj --startup-project TeamManager/TeamManager.csproj --context TeamManager.Data.ApplicationDbContext --configuration Debug 20240124212353_azure
Could not execute because the specified command or file was not found.
Possible reasons for this include:
* You misspelled a built-in dotnet command.
* You intended to execute a .NET program, but dotnet-ef does not exist.
* You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
4 replies
CC#
Created by IcyIme on 1/10/2024 in #help
blazor implementing 404 page
blazor web app .net 8 not triggering <NotFound> tag how to fix it ?
@using BlazorApp33.Components.Account.Shared
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(Layout.MainLayout)">
<NotAuthorized>
<RedirectToLogin />
</NotAuthorized>
</AuthorizeRouteView>
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<h1>404 Not Found</h1>
</NotFound>
</Router>
@using BlazorApp33.Components.Account.Shared
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(Layout.MainLayout)">
<NotAuthorized>
<RedirectToLogin />
</NotAuthorized>
</AuthorizeRouteView>
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
<NotFound>
<h1>404 Not Found</h1>
</NotFound>
</Router>
3 replies
CC#
Created by IcyIme on 1/4/2024 in #help
Blazor roles
how to make role based auth in blazor server I've been trying to do it for 2 days and I didn't get anywhere, tutorials didn't help either chatgpt
2 replies
CC#
Created by IcyIme on 1/1/2024 in #help
problem with entityframework migration
error: An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Failed to load configuration from file 'C:\Users\peter\source\repos\BlazingBlog\BlazingBlog\appsettings.json'. Unable to create a 'DbContext' of type ''. The exception 'Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[BlazingBlog.Data.BlogContext]' while attempting to activate 'BlazingBlog.Data.BlogContext'.' was thrown while attempting to create an instance. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728 code:
using BlazingBlog.Data.Entities;
using Microsoft.EntityFrameworkCore;

namespace BlazingBlog.Data
{
public class BlogContext : DbContext
{
public BlogContext(DbContextOptions<BlogContext> options) : base(options)
{

}

public DbSet<Category> Categories { get; set; }
public DbSet<User> Users { get; set; }
public DbSet<BlogPost> BlogPosts { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
#if DEBUG
optionsBuilder.LogTo(Console.WriteLine);
#endif
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder.Entity<User>()
.HasData(
new User
{
Id = 1,
Email = "[email protected]",
FirstName = "Peter",
LastName = "Odak",
Salt = "dasdasdasd",
Hash = "dsalkdjasklfjdsalkjfdsakljfalskjdas"
}
);
}
}
}
using BlazingBlog.Data.Entities;
using Microsoft.EntityFrameworkCore;

namespace BlazingBlog.Data
{
public class BlogContext : DbContext
{
public BlogContext(DbContextOptions<BlogContext> options) : base(options)
{

}

public DbSet<Category> Categories { get; set; }
public DbSet<User> Users { get; set; }
public DbSet<BlogPost> BlogPosts { get; set; }

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
#if DEBUG
optionsBuilder.LogTo(Console.WriteLine);
#endif
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder.Entity<User>()
.HasData(
new User
{
Id = 1,
Email = "[email protected]",
FirstName = "Peter",
LastName = "Odak",
Salt = "dasdasdasd",
Hash = "dsalkdjasklfjdsalkjfdsakljfalskjdas"
}
);
}
}
}
4 replies
CC#
Created by IcyIme on 10/22/2023 in #help
❔ what learn first as beginerr blazor or asp.net
i want to go web dev route with c# and i am confused what is better learn first asp.net or blazor
17 replies
CC#
Created by IcyIme on 8/10/2023 in #help
❔ asp.net core with angular or blazor which pick?
i wonder what is better to start new projects... asp.net with angular or asp.net with blazor
33 replies
CC#
Created by IcyIme on 8/9/2023 in #help
next learn step is kinda confusing
I'm choosing between two frameworks, asp.net or .net maui, and I don't know what's better than learning... I thought about asp.net, but the learn path is quite confusing...
33 replies
CC#
Created by IcyIme on 7/17/2023 in #help
❔ problem with understanding delegates and generics
I have a problem with understanding delegates and generics and I'm already spending a lot of time on it and I don't understand where and in what situations to use it and why it's used and what it's good for... I went through several sources and none of them helped, thanks in advance for your help and i forgot interfaces
65 replies
CC#
Created by IcyIme on 3/16/2023 in #help
❔ BEST LEARNING PATH FOR ASP.NET
I am confused about asp.net and i do not know where to start with it.
8 replies