Columbine

Dia 20 de abril deste ano marca o 21º aniversário de um dos mais horríveis massacres em uma escola dos Estados Unidos. Naquele dia de 1999, Eric Harris e Dylan Klebold entraram na escola carregados…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Debug ASP.NET Core REST API in Azure App Services

This is a quick tutorial on how to launch your backend API in debug mode to azure app services.

After publishing my ASP.NET Core REST API to azure and fixing an initial SQL connection error, I tried doing some testing from Postman and from my locally hosted Angular frontend. What I ran into was a wall of 401 unauthorized errors. I figured at first that it might be a CORS problem, so I configured CORS in Azure to allow all origins. Same error. So everything seemed to be pointing to an invalid login, but what was weird is my DbInitializer class successfully created an admin user in the SQL DB, which I confirmed through doing a query in the Azure portal.

Through publishing my API to azure in debug mode and setting breakpoints, I was able to figure out that the password for the initial admin user was indeed not what the DbInitializer class supposedly set it to. Why that occurred? Honestly I didn’t bother to figure it out (I was ready to have this thing working, haha), but instead did a quick work around by disabling the user authentication, creating a new admin user from within the app, and then re-enabling user authentication and republishing. From that point everything worked as it should.

First set a break point in your code:

Next we need to publish the API to azure again but in debug mode:

Go ahead and click “Edit” under the select field, and you should get a pop up. Click settings and then select debug mode for “Configuration”:

Save the settings and then hit publish. Once your deployment is finished, you’ll need to attach a debugger to it.

Go to cloud explorer, make sure you’re signed into your azure account, which you should be since you just deployed it…Select the app service you want to debug and hit the “attach debugger” command found in the actions window.

You’re API will launch and you can now try making your HTTP request, trigger the breakpoint, and step through your code.

*Quick Tip: If you want to edit your code for testing, you’ll have to stop the debugger, edit it, and then republish it to azure.

I hope that helps.

Happy Debugging!

Add a comment

Related posts:

This moment in time is a rare glimpse into another world.

My grandpa was a vicar. When my grandma passed away after a long, tortuous battle with Alzeheimers, he couldn’t wait for the day he would be reunited with her again. Whilst he deeply mourned her…

Observe Shenzhen Through SZOIL

Briefly about myself, I am a nineteen-year-old local high school graduate, joining SZOIL in November for a one-month internship. Since I found that most of the interns’ posts are informationally…

Learning from the past year

2019 has been a difficult year. They say hardships are the biggest teachers. So, here is a brief summary of major things I learnt in 2019. (I have excluded professional and academic learning as it…