Simple ASP.NET Auth 项目教程

Simple ASP.NET Auth 项目教程

simple_aspnet_authSimple ASP.NET Authorisation boilerplate project. No EF, no database, no IdentityServer4 just a basic logging in system for both cookies and JWT and a controller with a set of examples.项目地址:https://gitcode.com/gh_mirrors/si/simple_aspnet_auth

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

simple_aspnet_auth/
├── docs/
│   └── images/
├── examples/
├── .gitignore
├── LICENSE
├── README.md
  • docs/: 包含项目文档的图片等资源。
  • examples/: 包含项目的示例代码。
  • .gitignore: Git 忽略文件配置。
  • LICENSE: 项目许可证文件,采用 MIT 许可证。
  • README.md: 项目说明文件。

2. 项目的启动文件介绍

项目的主要启动文件通常是 Program.csStartup.cs。由于引用内容中没有提供具体的文件内容,以下是一个典型的 ASP.NET Core 项目的启动文件结构:

Program.cs

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

namespace SimpleAspNetAuth
{
    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>();
                });
    }
}

Startup.cs

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

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

        public IConfiguration Configuration { get; }

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            // 添加认证和授权服务
            services.AddAuthentication("CookieAuth")
                .AddCookie("CookieAuth", config =>
                {
                    config.Cookie.Name = "UserLoginCookie";
                    config.LoginPath = "/Account/Login";
                });
        }

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }
}

3. 项目的配置文件介绍

项目的配置文件通常是 appsettings.json。以下是一个典型的配置文件示例:

appsettings.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*"
}
  • Logging: 配置日志级别。
  • AllowedHosts: 配置允许访问的主机。

以上是基于 simple_aspnet_auth 项目的典型结构和文件介绍。具体项目可能会有所不同,请根据实际情况进行调整。

simple_aspnet_authSimple ASP.NET Authorisation boilerplate project. No EF, no database, no IdentityServer4 just a basic logging in system for both cookies and JWT and a controller with a set of examples.项目地址:https://gitcode.com/gh_mirrors/si/simple_aspnet_auth

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

尤琦珺Bess

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

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

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

打赏作者

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

抵扣说明:

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

余额充值