src/Web/WebhookClient/Startup.cs

(开头部分) 5KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

namespace WebhookClient;

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.AddSession(opt =>
            {
                opt.Cookie.Name = ".eShopWebhooks.Session";
            })
            .AddConfiguration(Configuration)
            .AddHttpClientServices(Configuration)
            .AddCustomAuthentication(Configuration)
            .AddTransient<IWebhooksClient, WebhooksClient>()
            .AddSingleton<IHooksRepository, InMemoryHooksRepository>()
            .AddMvc();

        services.AddControllers();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {

        var pathBase = Configuration["PATH_BASE"];
        if (!string.IsNullOrEmpty(pathBase))
        {
            app.UsePathBase(pathBase);
        }

        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Error");
            // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
        }
        app.Map("/check", capp =>
        {
            capp.Run(async (context) =>
            {
                if ("OPTIONS".Equals(context.Request.Method, StringComparison.InvariantCultureIgnoreCase))
                {
                    var validateToken = bool.TrueString.Equals(Configuration["ValidateToken"], StringComparison.InvariantCultureIgnoreCase);
                    var header = context.Request.Headers[HeaderNames.WebHookCheckHeader];
                    var value = header.FirstOrDefault();
                    var tokenToValidate = Configuration["Token"];
                    if (!validateToken || value == tokenToValidate)
                    {
                        if (!string.IsNullOrWhiteSpace(tokenToValidate))
后面还有 88 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。