C
C#2y ago
dotnetdev

❔ Debugging asp.net core app from vscode

I am debugging asp.net core webapi from vscode, one endpoint is returning 404. when I trigger api from postman or swagger, it is not going to any breakpoint and directly returns 404. my questions is, what is the very first line of code that I should put breakpoint to get after triggering request from postman or swagger. Action method on Controller is not the first point for breakpoint, because some status returns even before them. I found a library for debugging endpoints, routes debugger, but it doesn't works on dotnet 7. but why should we use library, can't wait do that with debuggers.
13 Replies
Jayy
Jayy2y ago
If it's returning a 404 it means you haven't defined an endpoitn for that route So there is no place to put a breakpoint Make an endpoint for the route you are trying to hit
dotnetdev
dotnetdev2y ago
I know, but from which place that code is returning, there is a function right. why I can't put a breakpoint there.
Jayy
Jayy2y ago
There is no function in your code This is internal asp stuff returning a 404 There's no place to put a breakpoint because there is no code for it It's IL Just make an endpoint for your route lol, a 404 is simple
dotnetdev
dotnetdev2y ago
yes, but my concern is not that I can't handle 404, what I mean is, where is the first place to put breakpoint. and there was a route but still returning 404 on minimal apis was, because I have set RequiredAuthorization but not set Authorize on endpoint. and I solved it. but that took too much time from me scrolling throw my code. so I thought if there was a place to debug then I would know it is because of Authorization.
Jayy
Jayy2y ago
Required auth doesn't return a 404
dotnetdev
dotnetdev2y ago
and this is not only about 404, I can't debug how asp handles JWT tokens. there are lots of other sutffs.
Jayy
Jayy2y ago
It returns a 401 404 means "the requested route doesn't exist" Asp handles jwt tokens how you tell it too, if you don't want the defaults then you can pass callsbacks/providers to the UseJwt registration and put a break in that But auth is unrelated to 404
dotnetdev
dotnetdev2y ago
no no, what i mean is, I have set on MapGroup RequiredAuthorization, and to do so, then all endpoints belongs to that group should have [Authorize] or we should explicitly define allowanonymous, otherwise it will return 404, because endpoints thinks there is a route with authorization, but it is not there. if you want I can share a project with you, you can check.
Jayy
Jayy2y ago
otherwise it will return 404
No it won't. It will return a 401 Auth attr handles 401s
endpoint thinks there is a route with authorization but it is not there
I have no idea what this means Def share sample code if u have it
dotnetdev
dotnetdev2y ago
okay, will reproduce that and share code with you.
Jayy
Jayy2y ago
U have 20 mins before i think i lose cell service
dotnetdev
dotnetdev2y ago
okay, no problem. I am outside office. I will prepare that and share it with you. You can check when you have time.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.