System.Web.Http is not supported in .NET 8. You have to migrate from ASP.NET Web API to ASP.NET Core Web API. You are getting HttpError 404 because of this issue. Please see this link for more help: https://learn.microsoft.com/en-us/aspnet/core/migration/webapi?view=aspnetcore-8.0&tabs=visual-studio.
To solve your issue, try updating your Controller code as follows:
using Microsoft.AspNetCore.Mvc;
//using System.Web.Http;
namespace WebApiApplication1.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class MyController : ControllerBase
{
[HttpGet]
[Route("getdata")]
public IActionResult GetData(string param1, string param2)
{
if (string.IsNullOrEmpty(param1) || string.IsNullOrEmpty(param2))
{
return BadRequest("Both param1 and param2 are required.");
}
return Ok(new { Message = "Get: Data received", Param1 = param1, Param2 = param2 });
}
}
}