question

Simeon-6623 avatar image
0 Votes"
Simeon-6623 asked Simeon-6623 answered

Azure block some requests to .NET 6 API

Hello,

I'm migrating from ASP.NET Core 2.2 to ASP.NET Core 6 on Azure. I have several modified Raspberry Pi(StratoPI) that make request every 10 seconds to .NET Core portal after some operations response back.

On localhost, everything works perfectly fine, test it with Postman, but when I publish the project to Azure, the requests stop working, but with Postman request they still working when is already published.

I use Nlog, and there are no errors.

Is there can be some firewall that added to .NET Core 6, because on .NET Core 2.2 everything is working.


 My API code:
    
 [Route("api/[controller]")]
 [...ApiController]
 public class ...ApiController : ControllerBase
 {
    private readonly ILogger<...ApiController> _logger;
    
    public ...ApiController(ILogger<...ApiController> logger)
    {
        _logger = logger;
    }
    
    [HttpPost]
    public string GetWithBody([FromBody] S...Get s...Get)
    {     
    }
 }

I've searched a lot of, but cannot find anything that can bring me to the solution of this.
Also catch some errors from Azure Log stream: HTTP Error 400.0 - Bad Request ... The request could not be understood by the server due to malformed syntax. which can be anything.
I think there is something that I have to add to Program.cs to unblock this request, but cannot find what can be.

I am grateful for any straw that will help me find the problem.


dotnet-aspnet-core-generaldotnet-aspnet-generaldotnet-aspnet-webpagesdotnet-iot
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @Simeon-6623,

Also catch some errors from Azure Log stream: HTTP Error 400.0 - Bad Request ...

For the 400 error, there are many reasons, such as the anti-forgery token was missing from the request header, validation error and so on.

So, you'd better to capture the request header and request body, then, it is easier to narrow down the problem.

On localhost, everything works perfectly fine, test it with Postman, but when I publish the project to Azure, the requests stop working, but with Postman request they still working when is already published.

Besides, from your description, the request still works well with the Postman, but not on Azure, you can use Fiddler to capture the request and compare the request, is there any difference?

1 Vote 1 ·

Thank you for your replay. Still struggling with this problem. And I'm exhausted and never faced such problem.

I have safe with Strato PI(version of raspberry PI), that send 2 json strings to two urls on every 10 seconds.

I've create test environment in Azure. Published .NET 6 version, the requested error in Azure Log Stream is to the Login Page, but with Postmans request is perfect.
Ok, I know .net core 2.2 version is working on live, so I published it also on the test and also not working with the same requested page, which means for me there is some firewall on Azure, which I cannot find where it is.

The request, what I've capture, there is no difference.

Thank you for, your time.

Best Regards!

0 Votes 0 ·

1 Answer

Simeon-6623 avatar image
0 Votes"
Simeon-6623 answered

It is done! Found the problem. The whole problem was one string.

The Safe send to the portal JSON, that contains TimeStamp which is long. This TimeStamp is never readed in the API, I don't need it, so it not appear as error in the portal as others and in the class is string, so I change from string to long and start working.

So the conclusion .NET 6 don't convert int to string as .net core 2.2 do.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.