Pokey
What's the correct way to handle state in a SignalR Hub?
I am going to implement a SignalR hub which will be connected to by a client application. The purpose of this being SignalR and not just HTTP requests is so that I can send messages from the server back to the client at any point without the need for something like port forwarding, just ad-hoc, and I will also use the connection to request general data too, so I don't need more than one connection to communicate data either direction.
I would like to authenticate the client with an API key when it connects, or allow it to connect unauthenticated so I can pop it up on my control panel and assign it a new API key and identity remotely (remote provisioning, essentially)
What would the correct way to do this be? I understand that sessions are not available as a result of "duplex messaging" which makes perfect sense, so my other idea was to do this with a scoped service to hold some state data for the connection, but as far as I can tell, the DI scope is not guaranteed especially if the hub is connected via HTTP polling instead of WS.
88 replies
Change ASP.NET response encoding from UTF-8 to ISO-8859-1?
Hi there,
I am building an application which requires the response
Content-Type
to be text/plain;charset=ISO-8859-1
instead of text/plain;charset=utf-8
.
If I force this with:
ASP.NET returns a 406 to all responses. There is no Accept
header coming from the client.
How may I achieve this?3 replies
Mapping controller to / without breaking other controllers
Hi there,
I would like to rename
HomeController
to DefaultController
and instead of going to /Default/Action
I would like to go to /Action
This should be simple, but I do not want to break routing for other controllers. The order of importance I wish to follow is controller name and then DefaultController
action name (If there is a DefaultController.Dashboard
action and a DashboardController.Index
action I would like DashboardController.Index
to take priority)
How might I best configure one or more MapControllerRoute
entries to permit this?
Thanks!1 replies
❔ EF Core LINQ - Many to Many Search with && and ||
Hi there,
I have a 3 table structure for file storage that I would like to search, consisting of the following:
I would like to search files by assigned labels. I want to provide AND and OR groups for this search, so a search by
LabelEntity.Id
might look like so:
(1 || 2) && (5 || 7 || 12) && 17 && (4 || 6)
I have struggled for a while to work out an efficient way to do this. I will always have the IDs of the labels I want to search by as provided in the example, those are looked up beforehand.
I'd like to formulate this into a fast, efficient linq query(s)42 replies
✅ Reference DLL by path in .NET Core?
I have a DLL I want to reference. It is installed by a third party application. I have the following in my .csproj:
I do not want to include the third party's DLL in my project output, so I have this turned off. Installation of the third party product is a prerequitite to this application functioning, and the path will always be the same so the DLL will always be available.
When doing this, .NET Core complains (at runtime) that
The system cannot find the file specified
and additionally lists the exact version it was looking for.
The third party makes minor patches to the DLL every few months, with no API breakage. We want to reference the DLL at whatever version it is currently at and just use it, but .NET Core seems to not even want to load a specific version let alone any version.17 replies
❔ SingalR Hub Bearer Token Auth
I am failing to see a simple way to add bearer token auth to a SignalR hub. The instructions on how to do this on the SignalR client are easy enough, and some examples show an
Authorize
attribute on the hub class, but I have added my own custom IAuthorizationFilter
attribute to the class (which is used and works fine with controllers) but it is ignored when calling into the hub.
What would the correct way to do SignalR bearer token auth be? Thanks!2 replies
❔ Check if appsettings.json or appsettings.Development.json
I need to write settings back to my configuration json during the operation of the current application. To achieve this, I open the appsettings.json file and write the newly serialised values. This works perfectly in production, but causes issues in development.
How can I tell which json file the current application is using at the topmost level? I know it is appsettings.Development.json when running in a development context, but I have not found a way to determine this whilst the application is running.
Thanks
12 replies
❔ [STILL UNSOLVED] Forms pointing to the current page retain route parameters - How do I clear them?
I have a controller action which loads a view. The contents of the view are paginated by a route parameter and some pagination controls. These work fine.
There is a search box which allows you to filter or refilter results. This search box is a form which does a GET to the exact same action. Essentially, the page initial load, pagination, and search box all GET the exact same action.
If I move to any page, let's say 5 for this example, then everything loads fine, but the form URL generated by
asp-controller asp-action
on the form points to the current action with the page route parameter set (the route parameter is part of the URL, like /Stuff
or /Stuff/0
for first page and /Stuff/5
for 5th page)
This means clicking Search to get new results automatically lands on Page 5. How can I correctly clear the previous route parameters? I would very much prefer not having to do asp-route-page="0"
. There could be many other parameters for filtering introduced later which I do not want to have to explicitly clear.
Thanks27 replies
✅ Obtain % Modulus divisor?
Quick mafs: I have a
decimal
type variable which will always be a whole number. I also have a list of objects which have a quantity field on them.
I would like to spread the decimal variable out evenly across each object in the list, and then whatever whole number remainder I have left I will deal with separately.
So if I have a value of 13, and I have 5 objects, I am not sure what calculations I need to do to end up with a value of 2 (per object) remainder 3.
Pretty sure I need to mod it in some way but not certain6 replies
❔ AES-GCM Key Generation
Good evening!
I'd like to use
AesGcm
to encrypt data, but I need a good and safe way to generate the keys. Is it okay to use Aes aes = Aes.Create()
and then aes.GenerateKey()
and aes.GenerateIV()
and then take the values from that and use them with AesGcm
or is this not recommended for any reason?
Thanks!12 replies
❔ Disable Swagger index.html Routing
I have just added and configured Swagger on my project with a custom rote, however, when launching my app on Debug, Swagger has taken over the root route
/
and redirects it to /index.html
which is 404 because of my custom setup.
How can I tell swagger to quit redirecting this and to leave it alone, and let my other routes take over (as I have a controller mapped to /
)?32 replies
❔ Url.ActionLink is generating full URLs, not relative ones
I am using all known laws of aviation, there is no way a bee... https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.urlhelperextensions.actionlink?view=aspnetcore-6.0 the method should only produce a full URL if the Host and Protocol parts are provided. As you can see, they are not, and when inspecting the method in my IDE it says the default values for these parameters is
@Url.ActionLink("ActionName", "ControllerName", new { Route = "values" })
in my .cshtml views to generate links which I then put into the src of img tags and video players.
After deploying my application and placing it behind a proxy, Url.ActionLink is generating full, non-relative URLs with the protocol and hostname. This is not at all what I want to achieve, I need those paths to be relative.
According to null
.
How can I stop ActionLink from generating full URLs?3 replies
EF Core - Code First - Add new non-null column to existing table with existing data
Hi there,
I would like to add a new non-null column to an existing table which contains existing data. This is a simple Created field, and I want to set it to DateTime.UtcNow for all existing rows.
Of course, if I just add the column and create the migration, this will not work well as the migration will fail with a constraint error.
The common solution I see for this is to add it as a nullable in one migration, populate the data using seeding and then make it non-nullable in another migration.
I don't really want to use seeding, I'd rather just have the migration add it as a nullable column, do some kind of update to set all the missing values then immediately make it non-nullable, all in one migration.
Is this possible? Thanks!
17 replies
Many to Many Matches and Exlusions
Hi there,
I have 3 tables, Items, Tags and ItemTagMappings.
Each item can have many tags, and each tag can be associated with many items.
ItemTagMappings is a 3 column table with it's own ID as PK, and two FKs, the Item ID and the Tag ID.
I have two lists of Tag IDs. Ones to match and ones to exclude. I need to find the list of items which has every single one of the includes, but if it has any of the excludes it shouldn't match.
I have this working perfectly and fast with Includes only. Trying to get the excludes to work on top of that is nearing impossible. Please could I get some help?
2 replies
EFCore Cascade Delete when set to DeleteBehaviour.Restrict
Hi,
I would like to force a cascade delete of all DB entries related to the entry I want to delete.
The database is configured to restrict deletions rather than cascade, however I know using the SQL syntax it is possible to override this and force a cascade. How might I achieve this in EFCore?
Thanks!
36 replies
Detect binary exists in environment PATH
Hi there!
I'm building an application which relies on FFMpeg and FFProbe binaries to be present and accessible in a directory in the system PATH.
This application will be working across multiple platforms, so on Windows, those binaries might just be dumped in a folder which is in the system PATH environment variable, and on Linux those binaries might be installed as part of a package, and again therefore placed into a directory which is included in the system PATH environment variable.
These binaries are prerequisite to my application working, so I would like to detect they are present when starting the application, so I may quit with an error if they do not.
The trouble is, using File.Exists("ffmpeg.exe") or File.Exists("ffmpeg") does not respect the system PATH (understandably!) so I am not sure how I can check these binaries are present?
11 replies
Project Structure Advice - Common Solution without NuGet
Please could I get some project structure advice? I'd like to build a project which consists of multiple solutions. I'm splitting down a rather large product into multiple separate solutions - Authentication, Frontend, Backend and Shared. The first three all need to reference Shared, but must not reference each other.
How should I let these three solutions' projects reference the Shared solution (which will also be multiple projects) without packaging and publishing the Shared projects as NuGet packages?
Of course, I could just add the projects from Shared to each other solution that needs to reference them, but this is kinda messy, and would also rely on relative paths on disk which may not apply to other collaborators on the project.
4 replies