© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
6 replies
alkasel#159

✅ Controller method can be invoked from Edge and Postman but not by Firefox

Hi,
I've the following server controller:

[Route("[controller]")]
[ApiController]
public class ProductionOrderController : ControllerBase
{
    // ...

    [HttpGet("GetCount")]
    public async Task<ActionResult<string>> GetCount() {
        try {
            int result = await _productionOrderDAL.GetCountAsync();
            return result.ToString();
        } catch (Exception ex) {
            Console.WriteLine(ex.ToString());
            return new StatusCodeResult((int)HttpStatusCode.InternalServerError);
        }
    }
}
[Route("[controller]")]
[ApiController]
public class ProductionOrderController : ControllerBase
{
    // ...

    [HttpGet("GetCount")]
    public async Task<ActionResult<string>> GetCount() {
        try {
            int result = await _productionOrderDAL.GetCountAsync();
            return result.ToString();
        } catch (Exception ex) {
            Console.WriteLine(ex.ToString());
            return new StatusCodeResult((int)HttpStatusCode.InternalServerError);
        }
    }
}


Client side (blazor wasm) I invoke such method as follows:
private async Task MyMethod() {
    try {
        Task<HttpResponseMessage> t1 = _httpClient.GetAsync("ProductionOrder/GetCount");
        HttpResponseMessage response = await t1;
        string countStr = await response.Content.ReadAsStringAsync();
        int count = int.Parse(countStr);
        
        // ...
        
    } catch (Exception e) {
        Console.WriteLine(e.ToString());
    }
}
private async Task MyMethod() {
    try {
        Task<HttpResponseMessage> t1 = _httpClient.GetAsync("ProductionOrder/GetCount");
        HttpResponseMessage response = await t1;
        string countStr = await response.Content.ReadAsStringAsync();
        int count = int.Parse(countStr);
        
        // ...
        
    } catch (Exception e) {
        Console.WriteLine(e.ToString());
    }
}


If I launch the server and edge client, the latter retrieves the integer value. Same with Postman.
Using Firefox, on the other hand, I have that the request is sent, the controller returns the correct integer value (I can see that debugging) but it seems like the client is not receiving the answer: from developer tools, there is no status code as well as response header. The "response" tab in developers tool shows the client index.html page with an error:
<!DOCTYPE html>
    ...
      <body>
          <div id="blazor-error-ui">
              An unhandled error has occurred.
              <a href="" class="reload">Reload</a>
          </div>
      </body>
     ...
<!DOCTYPE html>
    ...
      <body>
          <div id="blazor-error-ui">
              An unhandled error has occurred.
              <a href="" class="reload">Reload</a>
          </div>
      </body>
     ...


And of course the parsing fails.

Please note that the controller has another method, a get request returning a list of items, and in that case firefox client retrieves the list of items successfully.

Could you please give me a hand?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

method are not stored in object but can be called from object?
C#CC# / help
12mo ago
Event not being invoked
C#CC# / help
2y ago
API request, working in Postman but not C#
C#CC# / help
3y ago
Make a method acessable by scripts extending it, but not by outside scripts
C#CC# / help
3y ago