kank commited on
Commit
760a5b2
·
verified ·
1 Parent(s): 24f2fa2
Controllers/HomeController.cs ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using Microsoft.AspNetCore.Mvc;
2
+
3
+ namespace MyMvcApp.Controllers
4
+ {
5
+ public class HomeController : Controller
6
+ {
7
+ public IActionResult Index()
8
+ {
9
+ return View();
10
+ }
11
+ }
12
+ }
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 构建阶段
2
+ FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
3
+ WORKDIR /src
4
+ COPY MyMvcApp.csproj ./
5
+ RUN dotnet restore MyMvcApp.csproj
6
+ COPY . .
7
+ RUN dotnet publish MyMvcApp.csproj -c Release -o /app/publish
8
+
9
+ # 运行阶段
10
+ FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
11
+ WORKDIR /app
12
+ COPY --from=build /app/publish .
13
+ EXPOSE 7860
14
+ ENV ASPNETCORE_URLS=http://+:7860
15
+ ENTRYPOINT ["dotnet", "MyMvcApp.dll"]
MyMvcApp.csproj ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ <Project Sdk="Microsoft.NET.Sdk.Web">
2
+
3
+ <PropertyGroup>
4
+ <TargetFramework>net9.0</TargetFramework>
5
+ <Nullable>enable</Nullable>
6
+ <ImplicitUsings>enable</ImplicitUsings>
7
+ </PropertyGroup>
8
+
9
+ </Project>
Program.cs ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var builder = WebApplication.CreateBuilder(args);
2
+ builder.Services.AddControllersWithViews();
3
+ var app = builder.Build();
4
+
5
+ if (!app.Environment.IsDevelopment())
6
+ {
7
+ app.UseExceptionHandler("/Home/Error");
8
+ app.UseHsts();
9
+ }
10
+
11
+ app.UseHttpsRedirection();
12
+ app.UseStaticFiles();
13
+ app.UseRouting();
14
+ app.UseAuthorization();
15
+
16
+ app.MapControllerRoute(
17
+ name: "default",
18
+ pattern: "{controller=Home}/{action=Index}/{id?}");
19
+
20
+ app.Run();
Views/Home/Index.cshtml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ @{
2
+ ViewData["Title"] = "Home Page";
3
+ }
4
+
5
+ <h1>Hello from .NET Core 9.0 MVC on Hugging Face!</h1>
6
+ <p>This is the simplest MVC site.</p>