Pokey
Pokey
CC#
Created by Pokey on 12/5/2023 in #help
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
CC#
Created by Pokey on 10/7/2023 in #help
❔ 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:
public class LabelEntity
{
public uint Id { get; set; }
public string Name { get; set; }
}

public class FileEntity
{
public uint Id { get; set; }
public string Md5Sum { get; set; }
public string Name { get; set; }
public string Location { get; set; }
}

public class FileLabelMappingEntity
{
public uint Id { get; set; }
public uint LabelId { get; set; }
public LabelEntity Label { get; set; }
public uint FileId { get; set; }
public FileEntity File { get; set; }
}
public class LabelEntity
{
public uint Id { get; set; }
public string Name { get; set; }
}

public class FileEntity
{
public uint Id { get; set; }
public string Md5Sum { get; set; }
public string Name { get; set; }
public string Location { get; set; }
}

public class FileLabelMappingEntity
{
public uint Id { get; set; }
public uint LabelId { get; set; }
public LabelEntity Label { get; set; }
public uint FileId { get; set; }
public FileEntity File { get; set; }
}
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
CC#
Created by Pokey on 10/3/2023 in #help
✅ 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:
<Project>
...
<ItemGroup>
<Reference Include="MyDll">
<HintPath>C:\Program Files\Vendor\Product\MyDll.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
...
</Project>
<Project>
...
<ItemGroup>
<Reference Include="MyDll">
<HintPath>C:\Program Files\Vendor\Product\MyDll.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
...
</Project>
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
CC#
Created by Pokey on 9/13/2023 in #help
❔ ✅ Parsing path into parts with varying separators?
The traditional way to do this would be
string myPath = "C:\\Users\\Me\\Desktop";
string[] myPathParts = myPath.Split(Path.DirectorySeparatorChar);
string myPath = "C:\\Users\\Me\\Desktop";
string[] myPathParts = myPath.Split(Path.DirectorySeparatorChar);
But what if the path uses / instead of \ because as far as I am aware Windows will understand this, but that wouldn't be the DirectorySeparatorChar? Thanks!
9 replies
CC#
Created by Pokey on 8/10/2023 in #help
❔ 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
CC#
Created by Pokey on 8/8/2023 in #help
❔ 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
CC#
Created by Pokey on 4/24/2023 in #help
❔ [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. Thanks
27 replies
CC#
Created by Pokey on 4/21/2023 in #help
✅ 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 certain
6 replies
CC#
Created by Pokey on 3/19/2023 in #help
❔ 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
CC#
Created by Pokey on 11/19/2022 in #help
❔ 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
CC#
Created by Pokey on 11/14/2022 in #help
❔ Convert relative URI string to route
Is it possible to take a relative URI string, for example /Api/RetrieveById/1?search=hello and split it into: Controller: Api Action: RetrieveById RouteValues: id = 1, Search = "hello"
4 replies
CC#
Created by Pokey on 11/10/2022 in #help
❔ Url.ActionLink is generating full URLs, not relative ones
I am using @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 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 null. How can I stop ActionLink from generating full URLs?
3 replies
CC#
Created by Pokey on 11/7/2022 in #help
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
CC#
Created by Pokey on 11/6/2022 in #help
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
CC#
Created by Pokey on 11/4/2022 in #help
EF Primary Key - int, uint, long or ulong?
I want to hold lots and lots of rows in my Postgres database. I assume I would be best advised configuring my entities and migrations to use a ulong as the Primary Key?
13 replies
CC#
Created by Pokey on 11/2/2022 in #help
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
CC#
Created by Pokey on 11/1/2022 in #help
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
CC#
Created by Pokey on 10/14/2022 in #help
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
CC#
Created by Pokey on 10/6/2022 in #help
Blazor WASM - Hosted Services During Debug
Hi there, I have a hosted service which I would like to run during debug in order to watch and hot-compile my SASS stylesheets. Because this is a hosted service, adding it to the Program.cs isn't particularly useful as this runs in the browser, so no watching for my SASS files takes place. Is there a way, during debug, to run the hosted service on the "server side" (in the IDE) so that my SASS files get hot compiled?
3 replies