oe
IIS Cold Start / State Issues After 10 Minutes
I'm having "cold start/state" issues with my IIS (& ASP.NET Core API). After around 10 minutes of idleness, if I make a request to my IIS, I get issue "curl: (6) Could not resolve host: curl. curl: (56) Recv failure: Connection was reset" OR on Fiddler "HTTP/1.1 504 Fiddler - Receive Failure". After making that request, if I make more requests, it works fine. It's just the first request that doesn't work.
I have tried everything I have found: StartMode to AlwaysRunning, doAppInitAfterRestart (preload) with a non authenticated controller/endpoint, setting application pool idle timeout to 0 (and process suspended instead of terminated), disabling application pool recycling (set to 0)
Extra context in case it helps:
- I am using BasicAuthentication (configured in code) - https://raw.githubusercontent.com/cornflourblue/aspnet-core-basic-authentication-api/master/Helpers/BasicAuthenticationHandler.cs
- I am using Entity Framework Core & SQL Server (injected into the controller from the endpoint I am calling)
- I am using IIS on Win Server 2022. Jenkins for CI/CD. Don't use linux because I have unit tests with Selenium/Chrome automations, which I want to be able to see in action. Don't use Kestrel since I have found it really hard to integrate with Jenkins (for start/stop), and since I like hosting my Angular app in the same "context/program"
Since using IIS I have had nothing but headaches. I have worked with Python/Flask, Gunicorn, Jenkins and its been a breeze, but I really wanted to make .NET work for my startup, so I've pushed on and on through headache and headache. I cannot for the life of me sort this last issue out.
Any help would be incredibly appreciated
73 replies
Entity Framework Cascade Delete Issues
Hi guys, I want to be able to save this as a single operation:
However, for some reason, ProductNodes does not get re-added if I remove the first "SaveChangesAsync".
The reason I want it in a single operation, is I don't want downtime where there is no VirtualStore list or ProductNode list between the both operations.
1 replies
Track Thread/Task Progress through SignalR/WebSockets
I have an ASP.NET Web Core API and an Angular project both connected.
In the dashboard of my Angular app, I want to have a section where I can see all the tasks that are running, and what exactly they are executing.
For example, if I call endpoint /CreateTask, it will fire off a webrequest every second for 60 seconds, and when the status property acquired from the http response is complete, it will save it in the database, then send an email etc (I just made this up).
I want to be able to see in my dashboard:
TaskName | CurrentAction
CreateTask-1512 | StartRequestLoop()
CreateTask-5191 | AddToDatabase()
I have thought of the following:
- Launch a thread at the very start of the WebAPI launch.
- Within this thread, start a WebSocket/SignalR
- Every X seconds, query all the open Threads (maybe there some library/.NET api for this?) and collect their ID & stacktrace, then format the stacktrace so it prints out JustMyCode (the first method call from my own code) and post it to SignalR
- Connect to SignalR/WebSocket in Angular and show table
I think my approach seems viable, although I wonder if I could be doing something in an easier/more efficient way?
Any suggestions are greatly appreciated
2 replies
Refactoring Injected Singleton for Authentication and HttpClient Usage
Everytime a
TestPaymentsService
is created, it should be authenticated. Instead of constantly calling .Authenticate, I want to be able to do it once at the start of my app's lifetime.
Instead of firing off a web request in the constructor (since it cannot be async), I decided to create a static create method that creates the instance to be able to authenticate.
However, I now realised its a bad practice to recreate a HttpClient in every method inside TestPaymentsService
. Although I registered a IHttpClientFactory
using builder.Services.AddHttpClient();
in Program.cs
, I cannot inject it since I dont have a constructor.
I want to be able to create a TestPaymentsService
, inject it into DI and use it wherever I want without having to call Authenticate
method each time, since it was called at the very beginning.
How should I approach this? Current implementation:
Program.cs:
TestPaymentsService.cs:
3 replies
Debugger Breaks to External Files and Exception Handling Issue in C# .NET 8.0 with VS 2022
I am coding my project in .NET 8.0 in the new Visual Studio 2022 Preview version.
Whenever there is an exception within a try catch block, for some reason, the VS debugger breaks and brings me to files which are not from my project, such as:
Exception User-Unhandled:
System.Net.Sockets.SocketException
HResult=0x80004005
Message=The requested name is valid, but no data of the requested type was found.
Source=System.Net.Sockets
StackTrace:
at System.Net.Sockets.SocketAsyncEventArgs.<<DnsConnectAsync>g__Core|112_0>d.MoveNext()
C:\Users\FRZ\AppData\Local\SourceServer\8a3b989d075fe5e6b812cbdd0fa766804632a4fa333c1d383a1867bd743fd652\src\libraries\System.Private.CoreLib\src\System\Runtime\CompilerServices\AsyncTaskMethodBuilderT.cs
Not only is the exception not bringing me to my user code, but it is also breaking from within a try catch (handled exception). It should continue executing.
What is going wrong, and how can I fix this?
73 replies
❔ C# Exceptions Not Caught?
Why is this code causing Visual Studio to break if it is being ran in a try catch?
It takes me here and shows me this exception:
The issue is occuring here:
HttpResponseMessage httpResp = await Client.SendAsync(httpReq);
Regardless of the exception type, it should not be breaking in Visual Studio? I am running Visual Studio 2022 preview version8 replies
✅ Client needs filtering logic - what's the best way to implement?
I have two classes like so:
After my program runs, the List<VirtualProduct> Products variable is filled with objects and a JSON of it is returned to the client.
I want my client who knows nothing about coding to be able to filter products by writing in some language or query what objects he wants to keep in that list, based on certain conditions, like:
"CONTAINS toy", "EQUALS Best Toy In America", "NOT {{StoreName}}"
Should I implement this logic on my own, or use some sort of existing query language that C# can interpret / solution for this?
Thanks!
44 replies
GIT Question for company
Sorry if this is a really noob question, but I don't want to bother my manager and also I've never worked as a team on a Git project and never ran into this issue...
I have coded a branch1 on my company GIT repository.
After I have finished coding it, it is pending work review, so they haven't integrated it into master yet.
Now I have been told to code a new branch2.
However, now there are updates on main that are not in the branch1, and updates in the branch1 that are not in main.
I need both of these changes to update what I am doing in branch2.
What solution do I have apart from asking them to finish the pending work review and integrate branch1 to main and then pulling the new main from my side?
7 replies
❔ What unit tests should I create for my ASP.NET API Controller / project?
I am new to Unit Testing. I have watched a video on XUnit and FluidAssertions, but I am unsure as to what the "industry standards" of creating unit tests is like. Should you create one unit test per controller method? In my case, what unit tests would you create?
API Project: https://github.com/OEvans117/RequestConverter/tree/master/RequestConverterAP
API Controller: https://github.com/OEvans117/RequestConverter/blob/master/RequestConverterAPI/Controllers/RequestController.cs
XUnit Project: https://github.com/OEvans117/RequestConverter/tree/master/RequestConverterAPI.Tests
Thank you! 🙂
2 replies
❔ best design practice for this?
Hi everyone. I have a ConvertedRequest class that acts as an Entity Framework model for the database. Inside the class, there is an ID of type string (I want it to be alphanumeric 6 digits, not GUID). I have a method to generate this below. My question is what's the best design practice to reference this method? I am technically not gonna make more "Random" value methods, so was thinking static singleton, but the purpose of this project is to learn how to write with good design patterns
Including it in the Controller for the API just seems ugly and out of place
5 replies
Is this the right way to save state of my ASP.NET/Angular app as a URL?
I have an ASP.NET Core + Angular project.
Once a file is uploaded to my ASP.NET API, a JSON is returned which is used by the Angular frontend.
I want to be able to click a SAVE button in frontend, and save that exact state of the APP to a URL (ie: example.com/r/wrhwrthj).
I thought of a way to do this.
1) When the save button is clicked, the JSON is sent to an API: POST URL: /SaveState/ BODY: jsonString
2) The API uses entity framework to save the current state to a MySQL table of { StateID, StateValue }
3) If Angular detects a route of /r/{x}, it requests the JSON from /GetState?id={x}
Is this a good approach to the problem I'm trying to solve? Will appreciate all feedback. Thank you!
5 replies
✅ Best way to return Tuple<string, string> as an Array?
I have an interface called
IRequest
, with Tuple lists called:
Unfortunately, when I export a class that inherits IRequest
as JSON, it's then hard to iterate through Headers
and Cookies
, because Tuples in C# are treated like classes outside of it. (I'm using Angular to read the JSON).
What's the best solution to export that Tuple as an Array of strings in the JSON? Take into account I will have multiple classes that inherit IRequest, so a global solution that affects all classes would be perfect in that sense.61 replies
❔ Implement Angular in existing ASP.NET Core MVC project?
Hi,
I have an ASP.NET MVC web app that takes a file upload in and produces an output. It uses Razor, HTML and some simple javascript in a <script> tag.
I would like to recreate the project in Angular, React, Vue and lastly Blazor (instead of js) to test each framework out and see which one I like the best.
I am currently trying to implement Angular, but I believe my web app uses server side rendering (SSR) as it uses ASP.NET Core MVC pattern.
My question is: how do I implement Angular in my existing ASP.NET MVC project ?
My question is: how do I implement Angular in my existing ASP.NET MVC project ?
26 replies
Installing Docker and running ASP.NET project on Ubuntu Droplet led to ERR_CONNECTION_TIMED_OUT site
Anyone know what issue I had with Docker/NGINX when trying to run an ASP.NET site?
I must say before starting this was a production server for my site that was hosting a laravel API + vuejs webapp. It uses NGINX to do so.
Before I installed Docker I figured there might be issues with the server when doing so, so I saved all the /nginx/ folder data and I made a droplet snapshot (none of which helped to restore old state).
Then I installed docker, pulled my repository and ran the image using docker run.
I then visited my website, and it was completely crashed. Nothing would load. Everything would end up in ERR_CONNECTION_TIMED_OUT
So I uninstalled docker, that didn't help.
I tried replacing NGINX sites-enabled, .conf (every file) with the old version, didn't help.
Lastly, I restored the droplet snapshot using my hosting company, but that didn't help.
Anyone have any ideas why this might've happened?
2 replies