How can I change the HTTP status code from an app service? When returning data it returns 200 and if I throw an exception it returns 500.
I would like to return custom codes and basic ajax response, without any wrapped data. I tried adding DontWrapResult to my method declaration of my service interface but nothing changed, it still returned wrapped JSON.
Any help on this would be greatly received.
Thank you, David Hawkins
3 Answer(s)
-
0
Hi,
If you are using ASP.NET MVC 5.x / Web API then you need to add [DontWrapResult] to the application service interface, not to the class.
But you can not set HTTP return code in application layer because it's a web layer feature. If you want to take full advantage of HTTP protocol then you need to write a regular Controller/ApiController.
-
0
Hi,
I'm actually using Angular and WebAPI, is the NoWrap option possible still in the app service?
If not I can create a controller as you described but I don't know how to authenticate against it as authentication is done automatically in the Angular <-> AppService communication. Is there any guides on Angular <-> Custom controller auth, as I would like to access data such as tenantId from inside the controller but they are null.
Thanks for your help on this. Kind regards,
David Hawkins
-
0
hi
[DontWrapResult] attribute is valid for application services. But if you want to modify http result codes you need to write your own controller. Abp automatically does authentication stuff. Follow the link
<a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Web-API-Controllers">https://aspnetboilerplate.com/Pages/Doc ... ontrollers</a>