I have built a very simple .NET Core app (target framework = 2.0), which runs fine when debugging (localhost).....but when I run in docker container on prod server, everything works except the MVC routes.
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();
app.Run(async (context) =>
{
await context.Response.WriteAsync("Environment name: " + env.EnvironmentName);
});
}
app.UseStaticFiles() works fine....as /index.html path returns the relevant file.
Also the app.Run() command works, and returns for all routes that are not calls for static files......Im assuming because the app.UseMvcWithDefaultRoute(); middleware is not being recognized so its passing to the next/final middleware.
Below is my HomeController.cs
public class HomeController : Controller
{
public string Index()
{
return "Hello world!!....from Controllers(folder)/HomeController(folder)/Index(function)";
}
}
When I request route IP/home/index, it should come back with the Hello World message......it does when debugging but not when running in docker container
Below is my docker file:
FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM microsoft/aspnetcore:2.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "mpx.dll"]
UPDATE: I changed HomeController.cs Index method to below....but it didnt help
public class HomeController : Controller
{
[HttpGet]
public string Index()
{
return "Hello world!!....from Controllers(folder)/HomeController(folder)/Index(function)";
}
}