Cydo
Cydo
Explore posts from servers
CC#
Created by Cydo on 1/7/2025 in #help
✅ Can't get HTTPS to work for my api deployment.
I am following the Microsoft docs https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-9.0&tabs=linux-ubuntu step by step and I get the point where you set up nginx everything works when I'm on http, but the second i try to make anything go to https everything breaks, the connections time out and I can't get anything to work, I have no idea why. No working HTTPS
server {
listen 80;
server_name questbound.xyz www.questbound.xyz;

# Redirect all HTTP traffic to HTTPS
return 301 https://$host$request_uri;
}

server {
listen 443 ssl;
server_name questbound.xyz www.questbound.xyz;

# SSL Configuration
ssl_certificate /etc/letsencrypt/live/questbound.xyz/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/questbound.xyz/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

# Proxy to your backend API
location / {
proxy_pass http://0.0.0.0:5000; # Ensure the API is running here
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
server {
listen 80;
server_name questbound.xyz www.questbound.xyz;

# Redirect all HTTP traffic to HTTPS
return 301 https://$host$request_uri;
}

server {
listen 443 ssl;
server_name questbound.xyz www.questbound.xyz;

# SSL Configuration
ssl_certificate /etc/letsencrypt/live/questbound.xyz/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/questbound.xyz/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

# Proxy to your backend API
location / {
proxy_pass http://0.0.0.0:5000; # Ensure the API is running here
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
2 replies
CC#
Created by Cydo on 12/29/2024 in #help
Trying to understand proper error handling
I am trying to write my code to properly handle errors and I am getting so hyper fixated on it that I can't tell whether I'm making good decisions or not. I have rewritten the way my code base handles errors several times and I'm not sure what the right approach is anymore. I originally started using my own implementation of the result pattern, then realized I have this issue where the status code wasn't correct when returning errors, so I said maybe my implementation isn't that good so I looked for a library and settled on ErrorOr, but soon realized its the same issue, I dont understand how you can tell the "result pattern" that this error is a 401, 500, or 400 etc so I gutted that out and started writting my own custom exceptions and made a middleware that handles all the exceptions but now Im reading that you shouldn't throw errors when you now how to handle them and that throwing excessive erros will cause performance issues.
160 replies
CC#
Created by Cydo on 12/4/2024 in #help
How can I make FluentValidation return errors in camel case??
I have tried created an ValidationInterceptor and configuring my program.cs to return json in camel case but nothing seems to work
using FluentValidation;
using FluentValidation.Results;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Text.Json;
using FluentValidation.AspNetCore;

namespace CollabParty.Application.Common.Validators
{
public class CamelCaseValidationInterceptor : IValidatorInterceptor
{
// Before MVC validation
public ValidationContext<T> BeforeMvcValidation<T>(ControllerContext controllerContext, ValidationContext<T> context)
{
return context; // No changes before validation
}

// After MVC validation: Convert the property names to camelCase
public ValidationResult AfterMvcValidation<T>(ControllerContext controllerContext, ValidationContext<T> context, ValidationResult result)
{
var camelCasedErrors = result.Errors.Select(error =>
new ValidationFailure(
JsonNamingPolicy.CamelCase.ConvertName(error.PropertyName), // Convert to camelCase
error.ErrorMessage,
error.AttemptedValue)
{
ErrorCode = error.ErrorCode,
CustomState = error.CustomState,
Severity = error.Severity
}).ToList();

return new ValidationResult(camelCasedErrors);
}

// These methods are not needed but can be left as no-ops
public IValidationContext BeforeAspNetValidation(ActionContext actionContext, IValidationContext commonContext)
{
return commonContext;
}

public ValidationResult AfterAspNetValidation(ActionContext actionContext, IValidationContext validationContext, ValidationResult result)
{
return result;
}
}
}
using FluentValidation;
using FluentValidation.Results;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Text.Json;
using FluentValidation.AspNetCore;

namespace CollabParty.Application.Common.Validators
{
public class CamelCaseValidationInterceptor : IValidatorInterceptor
{
// Before MVC validation
public ValidationContext<T> BeforeMvcValidation<T>(ControllerContext controllerContext, ValidationContext<T> context)
{
return context; // No changes before validation
}

// After MVC validation: Convert the property names to camelCase
public ValidationResult AfterMvcValidation<T>(ControllerContext controllerContext, ValidationContext<T> context, ValidationResult result)
{
var camelCasedErrors = result.Errors.Select(error =>
new ValidationFailure(
JsonNamingPolicy.CamelCase.ConvertName(error.PropertyName), // Convert to camelCase
error.ErrorMessage,
error.AttemptedValue)
{
ErrorCode = error.ErrorCode,
CustomState = error.CustomState,
Severity = error.Severity
}).ToList();

return new ValidationResult(camelCasedErrors);
}

// These methods are not needed but can be left as no-ops
public IValidationContext BeforeAspNetValidation(ActionContext actionContext, IValidationContext commonContext)
{
return commonContext;
}

public ValidationResult AfterAspNetValidation(ActionContext actionContext, IValidationContext validationContext, ValidationResult result)
{
return result;
}
}
}
2 replies
CC#
Created by Cydo on 11/28/2024 in #help
✅ Setup SendGrid to send emails, but not getting them
No description
3 replies
CC#
Created by Cydo on 11/27/2024 in #help
✅ How can I take 2 existing repos (client and backend) and combine them?
I've always made my frontend and backends separate repos, and would like to instead make set it up where the frontend and client are both in the same repo. But it doesnt seem as simple as just creating a parent folder with 2 subfolders one for frontend and one for backend and then or am I wrong? I assumed you'd have one .gitignore in the root instead of a .gitignore in each subfolder? Or because how .net has solutions is it more complex?
39 replies
CC#
Created by Cydo on 11/23/2024 in #help
✅ JTI not being pulled from payload when I am trying to validate token
I create an access token store all the claims i want on it and get an access token and this is what the payload looks like when its decoded Creating Access Token
private string CreateAccessToken(ApplicationUser user, string sessionId)
{
var tokenHandler = new JwtSecurityTokenHandler();
var key = Encoding.ASCII.GetBytes(_jwtSecret);

var tokenDescriptor = new SecurityTokenDescriptor
{
Subject = new ClaimsIdentity(new Claim[]
{
new Claim(ClaimTypes.Name, user.UserName.ToString()),
new Claim(JwtRegisteredClaimNames.Jti, sessionId),
new Claim(JwtRegisteredClaimNames.Sub, user.Id),
}),
Expires = DateTime.UtcNow.AddMinutes(30),
SigningCredentials = new(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature),
Issuer = "https://localhost:7059",
Audience = "http://localhost:5173"
};

var token = tokenHandler.CreateToken(tokenDescriptor);
var tokenStr = tokenHandler.WriteToken(token);

return tokenStr;
}
private string CreateAccessToken(ApplicationUser user, string sessionId)
{
var tokenHandler = new JwtSecurityTokenHandler();
var key = Encoding.ASCII.GetBytes(_jwtSecret);

var tokenDescriptor = new SecurityTokenDescriptor
{
Subject = new ClaimsIdentity(new Claim[]
{
new Claim(ClaimTypes.Name, user.UserName.ToString()),
new Claim(JwtRegisteredClaimNames.Jti, sessionId),
new Claim(JwtRegisteredClaimNames.Sub, user.Id),
}),
Expires = DateTime.UtcNow.AddMinutes(30),
SigningCredentials = new(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature),
Issuer = "https://localhost:7059",
Audience = "http://localhost:5173"
};

var token = tokenHandler.CreateToken(tokenDescriptor);
var tokenStr = tokenHandler.WriteToken(token);

return tokenStr;
}
{
"unique_name": "Test",
"jti": "SESS73ab5ea8-2c67-42a9-ba6e-96241dad5b0a",
"sub": "bababf79-a2bc-49b3-9690-206acd714bd0",
"nbf": 1732389177,
"exp": 1732390948,
"iat": 1732389177,
"iss": "https://localhost:7059",
"aud": "http://localhost:5173"
}
{
"unique_name": "Test",
"jti": "SESS73ab5ea8-2c67-42a9-ba6e-96241dad5b0a",
"sub": "bababf79-a2bc-49b3-9690-206acd714bd0",
"nbf": 1732389177,
"exp": 1732390948,
"iat": 1732389177,
"iss": "https://localhost:7059",
"aud": "http://localhost:5173"
}
7 replies
CC#
Created by Cydo on 10/25/2024 in #help
✅ When should you or shouldnt you return nested data in an api call?
Let's say I have a these tables in my database, Project, Members, Task, Comments and I want to return paginated data so a user can view all their projects, then view the tasks and members associated with the project and the comments associated with the individual tasks. Would you do this as all separate queries or do one query that returns all the data nested and paginated? Here's my current thought process.
- Load all Projects paginated - One api call only project data
- Once you have the list of Projects a user can click one

- When a Project page loads another api call will fire and get all the Tasks paginated.

Now this is where I get a little confused
- When you load the Task page the api should return all the Task data, but does it also return the Comments in the same api call? How would they be paginated?

- Or do you do a 2nd api call that returns all the comments paginated. Keeping every api call super specific and only doing one thing.
- Load all Projects paginated - One api call only project data
- Once you have the list of Projects a user can click one

- When a Project page loads another api call will fire and get all the Tasks paginated.

Now this is where I get a little confused
- When you load the Task page the api should return all the Task data, but does it also return the Comments in the same api call? How would they be paginated?

- Or do you do a 2nd api call that returns all the comments paginated. Keeping every api call super specific and only doing one thing.
13 replies
CC#
Created by Cydo on 9/19/2024 in #help
✅ How should updating Database work with Kanban style app work?
No description
7 replies
CC#
Created by Cydo on 9/16/2024 in #help
✅ Having trouble handling errors when registering a new user
So my application is a .NET web api with a React front end, and im trying to handle all my errors on the backend during the register process and I dont seem to understand how errors are handled. When a user signs up im trying to account for all possible issues they could run into. For example wrong password length, missing special characters, uppercase, etc and then the same for email for example is it a valid email, is there any mistakes in the email for instance test@test,com as opposed to [email protected] I noticed that modelstate is always valid with email part, but for password things seem to work. the error that gets thrown when the email is not in a correct format actually comes from here var result = await _userManager.CreateAsync(user, registerRequestDTO.Password); and it throws this error "Username 'test1@test,com' is invalid, can only contain letters or digits." and I can't seem to figure out how to make it handle this error correctly so that it is in the format below, I don't think I can just hard code it because what if a different error is thrown, i want it to always come back in the format, Key: ['array of errors', '...' ] like below.

"errors": {
"ConfirmPassword": [
"Passwords do not match."
]
},

"errors": {
"ConfirmPassword": [
"Passwords do not match."
]
},
But I'm not sure how to achieve that. This is what I set up for my code currently and that specific error always hits the ApplicationException I'll attach the code in a gist since there is so much of it https://gist.github.com/CydoEntis/2d9160d6867651f8209214334779a3fe
6 replies
CC#
Created by Cydo on 9/15/2024 in #help
✅ Unit of Work for just Repositories or Services as well?
When you create a unit of work and you add repositories inside of it so you aren't constantly newing up additional ones across your applications, should services also be added to the same unit of work? Another unit of work or not at all? I don't see the harm in adding services to the unit of work so would that be a valid thing to do or will that cause issues somehow?
1 replies
CC#
Created by Cydo on 9/14/2024 in #help
✅ How to hide sensitive data, like database credentials api keys etc
I know you enter this stuff in your appsettings.json, but from what I can see your apisettings.json gets stored in your gitrepo, so is there something like a .env file in the .NET ecosystem where i can store everything in there omit it from git and then load that data into appsettings.json? Everything I found so far is talking about setting the variables in an azure key vault or setting them inside of the terminal, am I missing something here? I'm just developing locally atm but even if i deploy this app, i dont think I will be using azure because of how expensive it is and would like to not use the key vault because of that, but at the same time i dont want any of this to be on my git repo for random ppl to potentially see as well.
16 replies
CC#
Created by Cydo on 9/6/2024 in #help
✅ What is considered enough knowledge to start applying?
No description
25 replies
CC#
Created by Cydo on 8/27/2024 in #help
✅ Why Red Underline on Views?
No description
15 replies
CC#
Created by Cydo on 8/18/2024 in #help
✅ MVC application routing issue.
Why does the following code not work
<div>
<a asp-route-productId="@product.Id"
class="btn btn-primary bg-gradient border-0 form-control">
Details
</a>
</div>
<div>
<a asp-route-productId="@product.Id"
class="btn btn-primary bg-gradient border-0 form-control">
Details
</a>
</div>
But this code does
<div>
<a href="@Url.Action("Details", "Home", new { productId = product.Id })"
class="btn btn-primary bg-gradient border-0 form-control">
Details
</a>
</div>
<div>
<a href="@Url.Action("Details", "Home", new { productId = product.Id })"
class="btn btn-primary bg-gradient border-0 form-control">
Details
</a>
</div>
54 replies
CC#
Created by Cydo on 8/10/2024 in #help
How to create migrations in rider, when you have multiple projects in one Solution?
No description
37 replies
CC#
Created by Cydo on 8/10/2024 in #help
✅ Rider Not Creating a New Project in an existing solution correctly?
No description
21 replies