chemitaxis chemitaxis - 9 months ago 68
ASP.NET (C#) Question

Request BinaryRead in ASP.NET 5 (MVC6)

I had this code working in ASP.NET MVC 5, but I can't make it works in ASP.NET MVC 6 (ASP.NET 5)

Can someone help me?

public EmptyResult PayPalPaymentNotification(PayPalCheckoutInfo payPalCheckoutInfo)
PayPalListenerModel model = new PayPalListenerModel();
model._PayPalCheckoutInfo = payPalCheckoutInfo;
byte[] parameters = Request.BinaryRead(Request.ContentLength);

if (parameters != null)

return new EmptyResult();

The error is in:

byte[] parameters = Request.BinaryRead(Request.ContentLength);

HttpRequest does not contain a definition for BinaryRead and no
extension method BinaryRead accepting a first argument of type
HttpRequest could be found (are you missing a using directive or an
assembly reference?).

I have tested somethings like this, but not working:



Edit: Similar quesiton -> Error in binary read


The HttpRequestFeature object now provides a body which is a stream. So this should work.

    public static byte[] ReadRequestBody(Stream input)
        using (MemoryStream ms = new MemoryStream())
            return ms.ToArray();

and then ...

 var paramArray = ReadRequestBody(Request.Body);