Simo
Simo
CC#
Created by Simo on 10/19/2023 in #help
❔ DIY logging methods
I'm working on an old old codebase and I've noticed it has effectively implemented its own logging class, to append timestamps and so on. The code has
Debug.Log("blah blah" + whatever + "blah blah" + whatever);
Debug.Log("blah blah" + whatever + "blah blah" + whatever);
all through it, and if debugging is turned off, the Log method just does nothing with the string. - this does get called maybe 800,000 times in a day, but mostly with the logging turned off. Am I right in saying that the calling code will allocate all the strings every time, even when the debug is turned off internally? i.e. it would be more efficient to not call debug in the first place, so we dont allocate that string 800,000 times day?
27 replies
CC#
Created by Simo on 7/27/2023 in #help
❔ What is happening under the covers to allow this to work
someRandomString.Split('.').Select(HttpUtility.HtmlDecode); From the definition of HtmlDecode, it has an anonymous constructor, and one which takes a 's' parameter for the string. How on earth is this linq working that it can somehow construct it and pass the string in and get the result?
11 replies
CC#
Created by Simo on 12/23/2022 in #help
❔ ModelState.IsValid
do I need to call this explicitly myself or does the framework call this when using webAPI? I would assume that its called automatically but its still possible for the JSON to end up de-serialized but still not be valid?
5 replies
CC#
Created by Simo on 12/19/2022 in #help
❔ Handling invalid uploads
If I make a controller, which accepts a file upload POST, which only accepts pdf. if someone uploads a .docx for example, and I throw the error, does this error get thrown only after the entire file is uploaded anyway? i.e. its a bit silly because they wasted their time uploading the file only to receive an error?
4 replies
CC#
Created by Simo on 12/14/2022 in #help
❔ multi-line strings
hi, if I have a string like
@"this
is a multi
line string!"
@"this
is a multi
line string!"
when my code is formatted, tabs get inserted into my string so it ends up like:
@"this
is a multi
line string!"
@"this
is a multi
line string!"
What is the best way around this? replacing new lines with \n?
17 replies
CC#
Created by Simo on 12/6/2022 in #help
❔ ef migration snapshots
If I use the same project to deploy to dev and then live, do I need to clear the model snapshots? it seems it may hold dev-relevant information in there and mess up the live migration (I've noticed some of our migrations appear to not be included on live now)
12 replies
CC#
Created by Simo on 10/28/2022 in #help
passing license keys to a unit test
I would like to use a 3rd party DLL which needs a license key passed in, however I cannot find a way to do this, as the unit test project seems to ignore launchSettings.json, and I don't want to hard-code the key anywhere in the test itself. on Live this comes from an environment variable
12 replies
CC#
Created by Simo on 10/11/2022 in #help
require `mfa` claim only when user has `TwoFactorEnabled`
Hi, I have setup multifactor in my dotnet core MVC API, I have it saving the tokens and validating on your mfa code on login. when you login and enter your code, I set a mfa claim, which I then check in an AuthorizationHandler. The thought was that with this AuthorizationHandler it will stop someone bypassing the mfa code-entry part of the 2-step login. However in my AuthorizationHandler I only want to validate the token if the mfa claim is there when the user has TwoFactorEnabled set on their user. I can't find an easy way to access the user information. A user without TwoFactorEnabled should still be able to access things Can anyone think of a solution to this?
2 replies
CC#
Created by Simo on 10/6/2022 in #help
does anyone have an example of using Google Authenticator authentication as part of a SPA?
There's a lot of examples using the baked in solution and ASP generated pages, however in a SPA solution it's more tricky to pick apart the auth
25 replies