I created my first .Net Core Web API and trying to deploy it to a remote IIS server. I use a create-react-app project for the front end.
When I debug locally and communicate with .Net Core WEB API, it works fine:
https://localhost:5001/api/notes
I use https://myapp.eastus.cloudapp.azure.com as my public URL (here myapp is an example), and everything looks fine on browser that the front end pages load correctly.
But when I testing backend APIs by fetching get on
https://myapp.eastus.cloudapp.azure.com/api/notes
I got 404.
The web.config on .Net Core Web API build folder:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\myapp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
And React web.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<staticContent>
<remove fileExtension=".js" />
<mimeMap fileExtension=".js" mimeType="application/javascript; charset=UTF-8" />
</staticContent>
<rewrite>
<rules>
</rules>
</rewrite>
</system.webServer>
</configuration>
UPDATED:
My DbContext EF Core instance:
using Microsoft.Extensions.Configuration;
using Microsoft.EntityFrameworkCore;
namespace Notes.DB
{
public class AppDbContext : DbContext
{
protected readonly IConfiguration Configuration;
public DbSet<Note> Notes { get; set; }
public AppDbContext(IConfiguration configuration)
{
Configuration = configuration;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(
Configuration.GetConnectionString("myDb1"));
}
}
}
And, appsettings.json in .Net Core Project:
{
"AppSettings": {
"Secret": ""
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"myDb1": 'I generated this string from Azure SQL Database'
}
}
My Controller code:
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Notes.Core;
using Notes.DB;
namespace myApp.Controllers
{
[ApiController]
[Route("[controller]")]
[Bind("Id,Username,Value")]
public class NotesController : ControllerBase
{
private readonly ILogger<NotesController> _logger;
private INotesServices _notesSerives;
private readonly AppDbContext _context;
public NotesController(ILogger<NotesController> logger, INotesServices notesSerives, AppDbContext context)
{
_logger = logger;
_notesSerives = notesSerives;
_context = context;
}
[HttpGet("", Name = "GetAllNote")]
public IActionResult GetAllNote()
{
return Ok(_notesSerives.GetAllNote());
}
}
}
What I did wrong? How to debug this?

https://myapp.eastus.cloudapp.azure.com/api/notes- Lex Lihttps://myapp.eastus.cloudapp.azure.com/api/notesgives me a 200 but returns an HTML doc, so I am guessing the URL is still wrong? - Stone