Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

cloudpassAppServiceBase change http status code #3580


User avatar
0
paradoxit created

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)
  • User Avatar
    0
    hikalkan created
    Support Team

    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.

  • User Avatar
    0
    paradoxit created

    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

  • User Avatar
    0
    alper created
    Support Team

    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>