Aspnetboilerplate: Dont Wrap result is not working with a non abp controller

Created on 31 Aug 2017  路  26Comments  路  Source: aspnetboilerplate/aspnetboilerplate

I've added DontWrapResult attribute above the controller as shown in the example below
and it keeps wrapping the result
server code

    [IgnoreAntiforgeryToken]
    [ApiExplorerSettings(IgnoreApi = true)]
[DontWrapResult(WrapOnError = false, WrapOnSuccess = false, LogError = true)]
    public class ReportsController : ReportsControllerBase, ITransientDependency
    {
        public ReportsController(IHostingEnvironment environment)
        {

        }

    }

response
->
{error: null,
result:{clientId: "111254-b556"},
clientId:"111254-b556",
success:true,
targetUrl:null,
unAuthorizedRequest:false,
__abp:true
}

I've other controllers which inherit from AbpController and they have the same attribute and they don't wrap the result only this controller that Inherits from non Abp Controller is not affected by the attribute.

problem

Most helpful comment

hi @hikalkan well, I saw the test code you wrote but we need only the attribute to work on the Telerik report base controller, however, I tried to add the below lines in the web module instead of the controller attribute

c# Configuration.Modules.AbpAspNetCore().DefaultWrapResultAttribute.WrapOnSuccess = false; Configuration.Modules.AbpAspNetCore().DefaultWrapResultAttribute.WrapOnError = false;

and the controller is working fine but this is not the right way as we stopped wrapping all results for all the controllers in the ABP web project .. any suggestions ?!

All 26 comments

if you want to use this attr. please inherit to the abpcontrollerbase

Hi,
I've exact same issue and unfortunately one of the important controllers is out of our control (Telerik Report Controller) and I can't inherit it from AbpController.
Anyway to make this controller Don't Wrap Result without affecting the whole system.
Thanks,

I will check this issue in a short time.

I suppose this is ASP.NET Core with latest ABP. Please write your framework and ABP version when starting an issue. Thanks.

Yes it's AspnetCore with latest ABP.

I created a test code: https://github.com/aspnetboilerplate/aspnetboilerplate/commit/0f16eaf7156faaf2f95004b8338bed9667f458f7

I could not repeat the problem (tried a few variations, this is the final state).

hi @hikalkan well, I saw the test code you wrote but we need only the attribute to work on the Telerik report base controller, however, I tried to add the below lines in the web module instead of the controller attribute

c# Configuration.Modules.AbpAspNetCore().DefaultWrapResultAttribute.WrapOnSuccess = false; Configuration.Modules.AbpAspNetCore().DefaultWrapResultAttribute.WrapOnError = false;

and the controller is working fine but this is not the right way as we stopped wrapping all results for all the controllers in the ABP web project .. any suggestions ?!

@ahmedhassieb in the unit test I added it to a controller (https://github.com/aspnetboilerplate/aspnetboilerplate/commit/0f16eaf7156faaf2f95004b8338bed9667f458f7#diff-96c4cab299a5ea4d86bfd15663a6e86cR32) and worked. Isn't that what you want?

@ahmedhassieb, is there any news on this?

Did you see the latest comment of @hikalkan?

I want to add a comment to this issue. I was first searching for anything related to the use of Telerik's .NET Core controls.

Then I got lead to this issue.

My problem is regarding the using of Grid control on a page, totally basic setup, with 2 columns, no fancy stuff.

The grid would not show the data that it received (it rendered rest of the grid fine), until I appended the below code to my method that outputs the JSON data:

[DontWrapResult(WrapOnError = false, WrapOnSuccess = false, LogError = true)]

Regards

@Znow this is expected because ABP wraps results by default and telerik expects the plain result. You can disable it globally for all actions if you want.

I managed to reproduce this.

It happens when the Controller subclass is not the memberInfo.DeclaringType class.

Workaround

You can override and call the base class methods, e.g. c4c0de2
c# [DontWrapResult] public class PersonsController : AbpODataEntityController<Person>, ITransientDependency { public override IQueryable<Person> Get() { return base.Get(); } }

Thanks @acjh,

So, to reproduce it:

  • Create an abstract Controller class, like MyBaseController, add an action inside it.
  • Derive a new controller, MyController, inherit from MyBaseController.
  • Add [DontWrapResult] to MyController (class level).

@alirizaadiyahsi can you test like that. We should fix this problem.

Here is the my test code

```c#
public abstract class MyBaseController : Controller, ITransientDependency
{
public virtual int Get()
{
return 42;
}
}

public class MyController1 : MyBaseController
{
[HttpGet]
[Route("BaseWrappingTestFromDerived/Get")]
public override int Get()
{
return base.Get();
}
}

[DontWrapResult]
public class MyController2 : MyBaseController
{
[HttpGet]
[Route("BaseDontWrapTestFromDerived/Get")]
public override int Get()
{
return base.Get();
}
}
```

And result is as we expected.

@alirizaadiyahsi That's the workaround.

Like #2253, the expected usage is to not override. The Route attribute in that test code is unnecessary.

[DontWrapResult] is also not working for me. I don't want the orchestration of the response, ABP doing for the response. Its fine for API controller but for OData controller, I need the raw response from Odata. How can I achieve this ?
@hikalkan @acjh

Which version of ABP are you on?

Abp.AspnetCore.Odata 3.4.0

This issue was fixed in ABP v3.5.0.

Okay

Thanks

@hikalkan @acjh I have an other issue, not getting the count of records if I am using the default wrapresult provided by the ABP. How can I get the count of records in Odata ?

Show code.

Here I'm not getting the total count in the response, if I am wrapping the result according to ABP response.
```c#
public class TaskConfigsController : AbpODataEntityController, ITransientDependency
{
public TaskConfigsController(IRepository repository)
: base(repository)
{
}
}

Response: 
```json
{
    "result": [{
        "tenantId": 2,
        "tenantWorkflowTransitionConfigId": 1,
        "module": "DoctorOnBoardingModule",
        "workflow": null,
        "fromState": "Init",
        "trigger": "Trigger_1",
        "toState": "Doctor Created",
        "smsTasks": [],
        "emailTask": [],
        "notificationTask": [],
        "anonymizeDataTask": [],
        "lastModificationTime": "2018-05-21T12:52:03.936368",
        "lastModifierUserId": null,
        "creationTime": "2018-05-21T12:52:03.93585",
        "creatorUserId": null,
        "id": 5
    }],
    "targetUrl": null,
    "success": true,
    "error": null,
    "unAuthorizedRequest": false,
    "__abp": true
}

Here is the code using [DontWrapResult], where the odata raw result giving me the total count
```c#
[DontWrapResult]
public class TaskConfigsController : AbpODataEntityController, ITransientDependency
{
public TaskConfigsController(IRepository repository)
: base(repository)
{
}
}

Response:
```json
{
    "@odata.context": "http://localhost:21021/odata/$metadata#TaskConfigs",
    "@odata.count": 6,
    "value": [{
        "TenantWorkflowTransitionConfigId": 1,
        "LastModificationTime": "2018-05-21T12:52:03.936368+05:30",
        "LastModifierUserId": null,
        "CreationTime": "2018-05-21T12:52:03.93585+05:30",
        "CreatorUserId": null,
        "Id": 5
    }]
}

@acjh Can you pls look into this ?

[DontWrapResult] seems to be working as expected.
That's a different issue, so open a new issue if you believe there is a problem and explain why clearly.

Was this page helpful?
0 / 5 - 0 ratings