niels
niels
CC#
Created by niels on 2/26/2024 in #help
Automate logging
In my ASP.NET application, I need to log that a certain action has taken place. Currently, I manually add a piece of code that does this. It takes information from the DbContext as well as the ServerCallContext. See the code snippet below, the relevant part is the adding of a row to the Auditlog. Is there a way to just automatically perform this action (e.g. by adding an attribute)? [Authorize(Policy = RightsConstants.TemplateControl)] public override Task<AddResponse> AddSmsTemplate(EyeClinicAdminShared.SmsTemplate request, ServerCallContext context) { var user = _dbContext.GetUser(); var clinic = _dbContext.GetClinic(); var template = _mapper.Map<Models.SmsTemplate>(request); template.Clinic = clinic; var entry = _dbContext.SmsTemplates.Add(template); _dbContext.AuditLogs.Add(new AuditLog { Action = "" + System.Reflection.MethodBase.GetCurrentMethod()?.Name, User = user, Clinic = clinic, IpAddress = context.Peer, RawData = request.ToString() }); _dbContext.SaveChanges(); return Task.FromResult(new AddResponse() {Id = entry.Entity.Id}); }
14 replies
CC#
Created by niels on 2/21/2024 in #help
Complex question
Let's say I have a list of tuples. Now I also have a dictionary that maps from string to a subset of these tuples. Is it possible to, on compile time get hints for a specific string (which is a key from the dictionary) which tuples are included (without me having to go to the source code and look into the mapping)?
6 replies
CC#
Created by niels on 11/8/2023 in #help
❔ Cross platform user settings for app.
If I want to set and read user settings for my application, what would be the best way to do that in a way that is cross platform?
16 replies
CC#
Created by niels on 10/24/2023 in #help
✅ Cors not adding headers on ASP.NET application
I have a asp.net core web app, that will receive calls from a different origin (different port). To test, I have the following code in the Program.cs of the ASP.NET application. var app = builder.Build(); app.UseCors(builder => { builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader(); }); app.UseAuthentication(); app.UseAuthorization(); app.CreateDbIfNotExists(); // Configure the HTTP request pipeline. app.MapGrpcService<PatientServiceGrpc>(); app.MapGrpcService<AuthenticateServiceGrpc>(); app.MapGrpcService<AdminServiceGrpc>(); app.MapGet("/", () => "Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909"); app.Run(); However, I can't make calls to the api through the frontend, since the responses don't contain the Access-Control-Allow-Origin header, even though I allow all origins. What am I missing here?
7 replies
CC#
Created by niels on 10/23/2023 in #help
❔ dotnet workload installed, but not detected during compilation
For a project I'm using wasm-tools. It works fine on my Manjaro machine with dotnet version 7.0.111. But on my Ubuntu 22.04 machine with version 7.0.112, the build process fails with the message that I'm missing the workload wasm-tools. However when using dotnet workload list. The workload wasm-tools shows right up. What could be the issue here?
3 replies