Base solution for your next web application
Open Closed

Read InputStream from Request #3967


User avatar
0
ajayak created

I want to access Request object in ApplicationService. As the AppService is not a MVC Controller, how can I do so? I am trying something like this:

var json = new StreamReader(Request.InputStream).ReadToEnd();

5 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    @ajayak, are you working on ASP.NET Core or MVC 5.x ?

  • User Avatar
    0
    ajayak created

    I'm using ASP.NET Core

  • User Avatar
    0
    alirizaadiyahsi created

    Hi @ajayak,

    you can use app services (this is the better way) for your example from client side, for example:

    Client side

    var userAppService = abp.services.app.user;
    var tenantAppService = abp.services.app.tenant;
    ...
    
    userAppService.sendAnyData(anyDataDto);
    

    App service

    public AnyReturnValue SendAnyData(AnyDataDto anyDataDto)
    {
        
    }
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ajayak,

    You can inject IHttpContextAccessor into your app service and use it to access HttpContext and it's Requet property.

  • User Avatar
    0
    ajayak created

    Hi @ismcagdas,

    IHttpContextAccessor solution worked for me :)