Pascal
Pascal
CC#
Created by clownshark5503 on 11/12/2024 in #help
VerifyHashedPassword always returns a Failed result
this is definitely the problem. you should be using string HashPassword(TUser user, string password) method on the IPasswordHasher<TUser> implementation.
17 replies
CC#
Created by clownshark5503 on 11/12/2024 in #help
VerifyHashedPassword always returns a Failed result
You need to ensure that the expected format marker is set when generating the Hash. How are you generating the Hash?
17 replies
CC#
Created by julian on 10/10/2023 in #help
❔ Docker: Dotnet restore just loading
You can do RUN ls in your container before the dotnet restore to see the file structure inside your container.
35 replies
CC#
Created by julian on 10/10/2023 in #help
❔ Docker: Dotnet restore just loading
I don't think / is normal here, your project is definitely not in the root folder of the container. Your project files are instead copied to /src, so it does not make sense to tell dotnet restore to restore a project at /BackendForFrontend.csproj when it is not there.
35 replies
CC#
Created by ₮ⱤØ₣Ⱡł₦Ɇ_฿Ⱡ₳₵₭ on 9/4/2023 in #help
For-Loop doesnt work.
the issue with your code is that threadCounter, is sometimes unassigned. So the compiler does not know what to do when the value is unassigned and yet you are trying to access a value from it. you can fix this by assigning a default value to threadCounter. Something like int threadCounter = 0 or whatever your default value is.
72 replies
CC#
Created by UnionRings ♪ on 6/17/2023 in #help
❔ Determine what variable is being referenced
You would have to use Unsafe.AreSame<int>(ref someRef, ref someVar) (https://learn.microsoft.com/en-us/dotnet/api/system.runtime.compilerservices.unsafe.aresame?view=net-7.0#system-runtime-compilerservices-unsafe-aresame-1(-0@-0@)) to compare the references in this case. You don't want to use ReferenceEquals(someRef, someVar) due to boxing for value types.
15 replies
CC#
Created by rallez on 6/10/2023 in #help
print out all pairs of natural numbers whose sum isequal to the entered number n
This can be accomplished with a single for loop. Try applying this suggestion from @R.
34 replies
CC#
Created by assaf on 6/9/2023 in #help
✅ can I show a form using a panel using c# .net form?
$close
4 replies
CC#
Created by WillowBear on 6/7/2023 in #help
❔ What is the appropriate way to confirm User ID for API
in your controller endpoint you have access to the User object. Which you can use to pass down the logged in user id User.FindFirstValue(ClaimTypes.NameIdentifier). If your service should only be used in an http scope, then you may go with one of the suggestions above.
25 replies
CC#
Created by electronic heartbreak. on 6/7/2023 in #help
❔ Get property from type
Type names can not begin with numbers
13 replies
CC#
Created by WillowBear on 6/7/2023 in #help
❔ What is the appropriate way to confirm User ID for API
You are correct, I had no idea you could define the contract as code first and the tooling would be able to understand it.
25 replies
CC#
Created by WillowBear on 6/7/2023 in #help
❔ What is the appropriate way to confirm User ID for API
can you show an example (C# example) where this is not the case?
25 replies
CC#
Created by ghoulam on 6/7/2023 in #help
✅ Containers orchestration
There are lots of content and topics to cover with container orchestration, since your aim is to learn you may want to consider the Kubernetes approach (it is the industry standard for container orchestration). On windows you can enable kubernetes using Docker Desktop and on linux you can install Minikube. Then again you will have to read through kubernetes docs, Getting Started. When you feel comfortable defining and deploying kubernetes resources, then you may want to take it a step further and try setting up a cluster.
7 replies
CC#
Created by ghoulam on 6/7/2023 in #help
✅ Containers orchestration
Is HA (High Availability) a requirement for your graduation project? Seems overkill, but the quickest solution is to use a cloud managed services like AKS (Azure Kubernetes Service), EKS (Amazon Kubernetes Service) or any other. But if this is just to run on your local machine then you may consider installing MiniKube and reading up on the Kubernetes docs.
7 replies
CC#
Created by WillowBear on 6/7/2023 in #help
❔ What is the appropriate way to confirm User ID for API
If your CategoryService is a singleton something like this could work.
public class CategoryService : ICategoryService
{
private readonly DataDbContext _context;
private readonly IHttpContextAccessor _httpContextAccessor;

public CategoryService(DataDbContext context, IHttpContextAccessor httpContextAccessor)
{
_context = context;
_httpContextAccessor = httpContextAccessor;
}

public async Task<List<CategoryDTO>> GetAll()
{
// this still breaks outside an http scope
string? _userId = _httpContextAccessor.HttpContext?.User.FindFirstValue(ClaimTypes.NameIdentifier);
return await _context.Categories.Where( c => c.UserId == _userId ).Select( c => new CategoryDTO()
{
Id = c.Id,
Name = c.Name
} ).ToListAsync();
}
}
public class CategoryService : ICategoryService
{
private readonly DataDbContext _context;
private readonly IHttpContextAccessor _httpContextAccessor;

public CategoryService(DataDbContext context, IHttpContextAccessor httpContextAccessor)
{
_context = context;
_httpContextAccessor = httpContextAccessor;
}

public async Task<List<CategoryDTO>> GetAll()
{
// this still breaks outside an http scope
string? _userId = _httpContextAccessor.HttpContext?.User.FindFirstValue(ClaimTypes.NameIdentifier);
return await _context.Categories.Where( c => c.UserId == _userId ).Select( c => new CategoryDTO()
{
Id = c.Id,
Name = c.Name
} ).ToListAsync();
}
}
But I suggest you redesign ICategoryService.GetAll to accept userId as a parameter. Here is an example below.
public interface ICategoryService
{
Task<List<CategoryDTO>> GetAll(string userId);
}

public class CategoryService : ICategoryService
{
private readonly DataDbContext _context;

public CategoryService(DataDbContext context)
{
_context = context;
}

public async Task<List<CategoryDTO>> GetAll(string userId)
{
return await _context.Categories.Where( c => c.UserId == userId ).Select( c => new CategoryDTO()
{
Id = c.Id,
Name = c.Name
} ).ToListAsync();
}
}
public interface ICategoryService
{
Task<List<CategoryDTO>> GetAll(string userId);
}

public class CategoryService : ICategoryService
{
private readonly DataDbContext _context;

public CategoryService(DataDbContext context)
{
_context = context;
}

public async Task<List<CategoryDTO>> GetAll(string userId)
{
return await _context.Categories.Where( c => c.UserId == userId ).Select( c => new CategoryDTO()
{
Id = c.Id,
Name = c.Name
} ).ToListAsync();
}
}
25 replies
CC#
Created by WillowBear on 6/7/2023 in #help
❔ What is the appropriate way to confirm User ID for API
Yes something may or may not be wrong with this service depending on your DI registration. If CategoryService is registered as a Singleton (which I assume you are from your use of IHttpContextAccessor ) then this code breaks, _userId will always have the same value after initial initialization. HttpContext is only present in an Http scope, so if you initialize CategoryService outside of an Http scope, _httpContextAccessor.HttpContext will return null. Also the [Authorize] attribute here does nothing, you need to add it to your endpoint: Http endpoint, controller endpoint, signalR or gRPC.
25 replies