开源项目教程:re-cap-project-with-csharp

开源项目教程:re-cap-project-with-csharp

re-cap-project-with-csharpAraba Kiralama Sistemi | Kodlama.io | Recap Project项目地址:https://gitcode.com/gh_mirrors/re/re-cap-project-with-csharp

1. 项目的目录结构及介绍

re-cap-project-with-csharp/
├── Assets/
│   └── ...
├── Controllers/
│   └── ...
├── Models/
│   └── ...
├── Views/
│   └── ...
├── appsettings.json
├── Program.cs
├── Startup.cs
└── ...
  • Assets: 存放项目所需的静态资源文件。
  • Controllers: 包含项目的控制器文件,负责处理用户请求。
  • Models: 包含项目的数据模型文件,定义数据结构和业务逻辑。
  • Views: 包含项目的视图文件,负责展示用户界面。
  • appsettings.json: 项目的配置文件,包含数据库连接字符串、日志配置等。
  • Program.cs: 项目的入口文件,负责启动应用程序。
  • Startup.cs: 项目的启动配置文件,负责配置服务和中间件。

2. 项目的启动文件介绍

Program.cs

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace re_cap_project_with_csharp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });
    }
}
  • Main 方法: 项目的入口点,调用 CreateHostBuilder 方法创建并运行主机。
  • CreateHostBuilder 方法: 配置并创建主机,使用 Startup 类进行启动配置。

Startup.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace re_cap_project_with_csharp
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                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.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
    }
}
  • Startup 类: 负责配置应用程序的服务和请求处理管道。
  • ConfigureServices 方法: 注册应用程序所需的服务。
  • Configure 方法: 配置 HTTP 请求处理管道,包括中间件的使用。

3. 项目的配置文件介绍

appsettings.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*"
}
  • Logging: 配置日志级别,包括默认、Microsoft 和 Microsoft.Hosting.Lifetime 的日志级别。
  • AllowedHosts: 配置允许访问应用程序的主机列表。

re-cap-project-with-csharpAraba Kiralama Sistemi | Kodlama.io | Recap Project项目地址:https://gitcode.com/gh_mirrors/re/re-cap-project-with-csharp

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

吕岚伊

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值