文章正文

.NET8.0 使用学习(一)创建.NET8.0项目

加入时间:2025/8/28 15:51:43
  • 选择:ASP.NET Core Web 应用(模型-视图-控制器)  双击下图或者点击下一步

  • 项目名称自己填写 ,选择自己项目保存位置 点击下一步
  • 框架选择.NET8.0 (长期支持),项目默认勾选配置HTTPS 看需要可以不勾选,后期可以配置  点击下一步

项目结构是这样的

下面是Program.cs的代码

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();

其中 app.UseHttpsRedirection();就是前面勾选配置HTTPS产生的,同时会在Properties/launchSettings.json文件中有代码

    "https": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "https://localhost:7079;http://localhost:5012",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },

点击上面的项目应该会正常运行,说明项目创建成功

字体大小[ ]

版权所有:有信心——uxinxin 我的个人网站欢迎常来!手机版(新站开启,请多多关照) 豫ICP备12017930号-1
 豫公网安备41910102000493号