Alex
Alex
Explore posts from servers
CC#
Created by Alex on 10/30/2024 in #help
Upload file with swagger ui crash
No description
13 replies
CC#
Created by Alex on 10/29/2024 in #help
Service layer exception or bool/error object
Should I throw an exception and catch it in global handler or try catch it in method and return bool/error object if I implement method on service layer?
4 replies
CC#
Created by Alex on 9/19/2024 in #help
help me find correct response model
No description
3 replies
CC#
Created by Alex on 8/16/2024 in #help
How to start test inside docker container from app?
Hi! I'm thinking of building an app similar to leetcode or codewars. The basic idea is user sends you task id and code and I should run tests on it somewhere. I think doing it in docker containers should work. Is it possible to start docker container and pass there input and then somehow get results? Is there a better solution?
38 replies
CC#
Created by Alex on 8/6/2024 in #help
✅ how to add horizontal scroll bar to code block?
What styles do I need to add to the code inside pre to make it scrollable?
2 replies
CC#
Created by Alex on 7/26/2024 in #help
e commerce database help
No description
2 replies
CC#
Created by Alex on 7/25/2024 in #help
✅ e-commerce app
Hello, Can you help me with e-commerce product attributes concept, please? I want to build pet project and utilize this feature. But I don't know how to design database the right way, I've checked open source project - nopCommerce, but it's overwhelmed with other features that I won't have in my project. Maybe you have a simple database design with fields that I can start with. Basically I want to have variations of product and categories
21 replies
CC#
Created by Alex on 7/12/2024 in #help
✅ Web API format for error response
What format do you usually use to respond with failure to the sent request? Do you return ModelState or ProblemDetails?
4 replies
CC#
Created by Alex on 7/12/2024 in #help
✅ e-commerce design
Hi, I want to create an eCommerce application. I want to be able to configure many variations of products, for example size, color, and etc. I think of product->variation->variation_option. The question is how can I handle different value types for variation option and filtering? For example, size can be a number from, color - string, in-stock - boolean
1 replies
CC#
Created by Alex on 7/2/2024 in #help
Recommend book/source
Hi, I know how to program small applications, but I want to learn how to build programs like file system explorer, task manager or notepad. Is there any book or source that teaches you system/application design and building with examples I mentioned about? I want to understand how to build application right way, and how they function.
8 replies
CC#
Created by Alex on 6/28/2024 in #help
✅ Refresh Token + JWT + Identity
Hi! I can't find a way how to implement refresh token part with Identity. Most tutorials online don't use Identity and write their own implementation. Should I extend identity user or is there a better way? I want to learn how it can be done the right way.
6 replies
CC#
Created by Alex on 6/28/2024 in #help
✅ Refresh token for Identity
Hi! What's the correct way to implement refresh token in AspNetCore Identity? Can I use .SetAuthenticationTokenAsync() for this purpose? I want to use in refresh-token endpoint to create new JsonWebToken after it expires.
1 replies
CC#
Created by Alex on 6/27/2024 in #help
✅ Web API redirect back to client
I have a GET route that handles external authentication. On the client I have anchor <a href="myapi:8080/sign-in/external/Google">Google</a> to sign in with Google. If authentication is successful I want to return cookie (I'll change it later) and redirect back to client. I have one option to provide returnUrl but I'm not sure if it is a right solution. How can I do it?
[HttpGet("sign-in/external/{provider}")]
public IActionResult External([FromRoute] string provider)
{
AuthenticationProperties props =
_signInManager.ConfigureExternalAuthenticationProperties(provider, "/api/Accounts/external-callback");

return new ChallengeResult(provider, props);
}

[HttpGet("external-callback")]
public async Task<IActionResult> ExternalCallback()
{
...
// if authentication is success
return Ok();
}
[HttpGet("sign-in/external/{provider}")]
public IActionResult External([FromRoute] string provider)
{
AuthenticationProperties props =
_signInManager.ConfigureExternalAuthenticationProperties(provider, "/api/Accounts/external-callback");

return new ChallengeResult(provider, props);
}

[HttpGet("external-callback")]
public async Task<IActionResult> ExternalCallback()
{
...
// if authentication is success
return Ok();
}
<AnchorButton
href={`${import.meta.env.VITE_API_URL}/accounts/sign-in/external/Google`}
>Google</AnchorButtom>
<AnchorButton
href={`${import.meta.env.VITE_API_URL}/accounts/sign-in/external/Google`}
>Google</AnchorButtom>
1 replies
CC#
Created by Alex on 6/25/2024 in #help
✅ How to get Options from DI
I configured options for google authentication CliendId and ClientSecret.
builder.Services.ConfigureOptions<GoogleOptions>();
builder.Services.ConfigureOptions<GoogleOptions>();
Here I want to get them from ServiceProvider but I don't know how. Should I create ServiceProvider var provider = builder.Services.BuildServiceProvider();?
builder.Services.AddAuthentication()
.AddGoogle((options) =>
{
options.ClientId = "";
options.ClientSecret = "";
});
builder.Services.AddAuthentication()
.AddGoogle((options) =>
{
options.ClientId = "";
options.ClientSecret = "";
});
14 replies
CC#
Created by Alex on 6/17/2024 in #help
What's wrong with my LINQ expression?
Hi! I'm trying to get data using LINQ expressions below. I use Sqlite
public async Task OnGetAsync()
{
var now = DateTimeOffset.Now;

LockedOutUsers =
await _userManager
.Users
.Where(u => u.LockoutEnd != null && u.LockoutEnd > now)
.OrderBy(u=>u.Email)
.ToListAsync();

OtherUsers = await _userManager
.Users.Where(u => u.LockoutEnd == null || u.LockoutEnd <= now)
.OrderBy(u => u.Email)
.ToListAsync();
}
public async Task OnGetAsync()
{
var now = DateTimeOffset.Now;

LockedOutUsers =
await _userManager
.Users
.Where(u => u.LockoutEnd != null && u.LockoutEnd > now)
.OrderBy(u=>u.Email)
.ToListAsync();

OtherUsers = await _userManager
.Users.Where(u => u.LockoutEnd == null || u.LockoutEnd <= now)
.OrderBy(u => u.Email)
.ToListAsync();
}
But I'm getting exception
InvalidOperationException: The LINQ expression 'DbSet<IdentityUser>() .Where(i => i.LockoutEnd != null && i.LockoutEnd.Value > __now_0)' could not be translated.
InvalidOperationException: The LINQ expression 'DbSet<IdentityUser>() .Where(i => i.LockoutEnd != null && i.LockoutEnd.Value > __now_0)' could not be translated.
56 replies
CC#
Created by Alex on 6/14/2024 in #help
✅ Malformed input: 321 is an invalid input length
I'm working with Asp.Net Core Identity. I use GeneratePasswordResetTokenAsync(user) to generate token and encode it with WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(token));. Next I decode encoded token with Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(encodedToken)) and get exception:
An unhandled exception occurred while processing the request.
FormatException: Malformed input: 321 is an invalid input length.
Microsoft.AspNetCore.WebUtilities.WebEncoders.GetNumBase64PaddingCharsToAddForDecode(int inputLength)
An unhandled exception occurred while processing the request.
FormatException: Malformed input: 321 is an invalid input length.
Microsoft.AspNetCore.WebUtilities.WebEncoders.GetNumBase64PaddingCharsToAddForDecode(int inputLength)
How can I fix my problem?
1 replies
CC#
Created by Alex on 5/19/2024 in #help
✅ Store data for the game
How can I efficiently store lines for the picture player draws? Each line contains color, line width and points (x,y). I have a group object that will have array of drawn linesбword players need to guess and state "drawing","choosing word", "idle". I need the data for players who join after the round started. I need the data between signalR calls
1 replies
CC#
Created by Alex on 5/16/2024 in #help
✅ SignalR client to client communication (chat)
Is it correct that I can't send messages from client to client directly using SignalR? Do I need to send http POST request to endpoint, then inside endpoint I get IHubContext and execute method ReceiveChatMessage? (Client code)

const onSubmit = (
values: SubmitMessageSchema,
reset: UseFormReset<SubmitMessageSchema>
) => {
// METHOD USERNAME MESSAGE
connection?.send("ReceiveChatMessage", "Alex", values.text);
reset();
};

const onSubmit = (
values: SubmitMessageSchema,
reset: UseFormReset<SubmitMessageSchema>
) => {
// METHOD USERNAME MESSAGE
connection?.send("ReceiveChatMessage", "Alex", values.text);
reset();
};
4 replies
CC#
Created by Alex on 5/15/2024 in #help
✅ what's the difference?
What's the difference between sending message to signalR endpoint directly and sending post to controller and execute it hubcinnection.sendasync method inside of it? I want to build game project based on signalr, one person draws the picture other guess what is it by typing it in chat. Can I use only one connection for both sending drawn pixels and chat messages? Should I send chat messages directly to signalR hub of to the post route of controller?
4 replies
CC#
Created by Alex on 5/12/2024 in #help
Storage for http request routes
In the method to search route I'll provide "Method" and "Path". Is there a better way to store routes that Dictionary<string,Dictionary<string,delegate>>?
1 replies