Web API published to Azure WebApp not browse-able

Viewed 18

I created a sample API and published onto the Azure WebApp(.NET 6, Std Tier) from the Visual Studio. However, the same is not browse-able and am not able to call the APIs, that works just fine from the Swagger documentation. Here is the same controller.cs

[Route("api/[controller]")]
[ApiController]
//[Authorize]
public class ProductController : Controller
{
    private readonly IProductService _productService;
    public ProductController(IProductService productService)
    {
        _productService = productService;
    }
    [HttpGet]
    public IActionResult GetProducts()
    {
        return Ok(_productService.GetProducts());
    }

    [HttpGet("{id}")]
    public IActionResult GetProduct(string id)
    {
        return Ok(_productService.GetProduct(id));
    }

    [HttpPost]
    public IActionResult AddProduct(Product product)
    {
        return Ok(_productService.AddProduct(product));
    }
}

Program.cs

using ProductAPI.Services;

    var builder = WebApplication.CreateBuilder(args);
    
    // Add services to the container.
    
    builder.Services.AddControllers();
    builder.Services.AddSingleton<IProductService, ProductService>();
    // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
    builder.Services.AddEndpointsApiExplorer();
    builder.Services.AddSwaggerGen();
    //builder.Services.AddMicrosoftIdentityWebApiAuthentication(builder.Configuration, "AzureAd");
    
    var app = builder.Build();
    
    // Configure the HTTP request pipeline.
    if (app.Environment.IsDevelopment())
    {
        app.UseSwagger();
        app.UseSwaggerUI();
    }
    
    app.UseHttpsRedirection();
    
    app.UseRouting();
    //app.UseAuthentication();
    //app.UseAuthorization();
    app.UseEndpoints(enpoints =>
    {
        enpoints.MapControllers();
    });
    
    app.Run();

Each time i get: **

This page isn’t working productapi-appservice.azurewebsites.net is currently unable to handle this request. HTTP ERROR 500

**

Got the issue FINALLY! My own Azure Web App did not have access to the underlying Cloud DB. Therefore, updating the firewall settings did the job!

0 Answers
Related