Ikinidae
Ikinidae
CC#
Created by Ikinidae on 11/13/2023 in #help
Two Factor Authentication with IdentityServer4
Hi all guys, I'm here again asking for your help! I have an api project where I've been asked to implement a two factor authentication and I did it this way. The first api has in input email and password and give in response the otp code (it's a test api so it doesn't matter that the code is given in the response for the moment); the second one has in input the otp code and give in response the access token. The message was too long so I have to put the code in the file 😦 The problem is that all of this works perfectly fine in local but gives some problems on frontend (Angular), there are some kind of problems with the cookie that is generated but not accepted by the browser, so my boss asked me to try something else, using the session instead of the cookie. Is this possible or correct? If u all have any kind of suggestions on everything pls tell me, I'm willing to improve! Thanks ✨
1 replies
CC#
Created by Ikinidae on 10/26/2023 in #help
❔ Serilog: how to write a file for single level
Hi guys! I've been asked to write log levels Information, Warning and Error in development, but each of them in one separated file, so that I have information.txt containing only Information logs, warning.txt containing only Warning logs, Error.txt containing only Error logs. This is my implementation at the moment (it works): In Program.cs:
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.UseSerilog((webHostBuilderContext, loggerConfiguration) =>
{
loggerConfiguration.ReadFrom.Configuration(webHostBuilderContext.Configuration);
});
});
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.UseSerilog((webHostBuilderContext, loggerConfiguration) =>
{
loggerConfiguration.ReadFrom.Configuration(webHostBuilderContext.Configuration);
});
});
in appsettings:
"Serilog": {
"MinimumLevel": "Information",
"WriteTo": [
{
"Name": "Console"
},
{
"Name": "File",
"Args": {
"path": "wwwroot/Logs/log.txt",
"rollingInterval": "Day",
"reatinedFileCountLimit": 14,
"restrictedToMinimumLevel": "Information"
}
}
]
},
"Serilog": {
"MinimumLevel": "Information",
"WriteTo": [
{
"Name": "Console"
},
{
"Name": "File",
"Args": {
"path": "wwwroot/Logs/log.txt",
"rollingInterval": "Day",
"reatinedFileCountLimit": 14,
"restrictedToMinimumLevel": "Information"
}
}
]
},
I have installed Serilog.Expressions package and read the docs, I know I have to use something like this
"Filters": [
{
"Name": "ByIncludingOnly",
"Args": {
"expression": "@l = 'Information'"
}
}
]
"Filters": [
{
"Name": "ByIncludingOnly",
"Args": {
"expression": "@l = 'Information'"
}
}
]
but I can't understand where it should be placed. I've tried placing it in Args or between Args and Name but it doesn't work, can somebody help me? 🥺
7 replies
CC#
Created by Ikinidae on 10/26/2023 in #help
❔ Controller routing with dynamic parameter
Hi all guys! That's my first post so I don't know if I'm doing anything wrong, in case let me know! I have an api project with a lot of api that are gonna be used for both a website (control panel) and a mobile app (for customers). My controllers are all like this:
[Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("1.0")]
[ApiController]
public class AgentController : ControllerBase
{
// my api
}
[Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("1.0")]
[ApiController]
public class AgentController : ControllerBase
{
// my api
}
that means that my url looks like this: https://localhost:5000/api/v1/Agent What I need is to specify in the url if that api will be used in app or web, so that my url will look like this: https://localhost:5000/api/web/v1/Agent That parameter has to be specified for every api just like [HttpGet("GetAgentById")]. I obviously searched on web but I haven't found anything 😦 Thanks a lot ❤️
6 replies