Ysehporp
✅ Sending an HTTP Exception in Web API
I am having some trouble with sending an HTTP exception in web api as it seems how its dont has changed over the course of different .net versions.
There seems to be an issue of what return type I have, but I found examples online where people were able to do it with an ActionResult.
I found examples which implemented it like this but it will not compile for me because it cannot convert the return type.
I have also tried what is shown on the learn microsoft page where it says essentially to do
However doing so causes my server to encounter an unhandled exception and cease to work.
What is the correct way of doing this in .net 6???
54 replies
❔ Encoding Confusion and string variables
Hello! I am trying to encrypt a string, send it between two clients, and then decrypt the string. Which sounds simple enough but where I've hit a snag is in string encodings, or so I believe.
I am using the following code to encrypt and decrypt my string (userPassWord)
This works if I run it in isolation and just pass the result from one into the other. However! Where I am hitting a snag is that I cannot send the encrypted string as a byte[] but I need to send it as a string instead. However whenever I convert that byte array to a string and then back, it ends up either being an incorrect blocksize or decoding incorrectly. Do any of you know how to do this? Thanks a ton!
6 replies
❔ WEBAPI [FromBody] Json with optional elements
I am building a .net Wep API application where I will be receiving requests where all of the data is in the JSON body. I understand this is not the preferred way to do this but this is how I have to do it for this application. I will receive a post from my frontend which essentially looks like this
My code is able to process this provided both startTimestamp and endTimestamp are occupied. However as they are optional attributes they will sometimes be absent from requests and in those cases I receive an error
I would like to be able to make these field not required but I am uncertain how.
My method which receives the request starts like this
21 replies
❔ Entity Framework duplicating primary key with seeded data.
I have set up a database with EF6 and as part of verifying that it is working I have seeded in some data. The problem is, when I try to add data from those classes with auto incrementing keys the code attempts to start at id=1 instead of id=6 to position itself after my seeded data. It throws an error complaining about being unable to save data because of a duplicate primary key. How can I force it to respect my seeded data?
9 replies