コード例 #1
0
ファイル: Startup.cs プロジェクト: simplifate/dlt-guardian
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            string connectionString = CurrentEnv.IsDevelopment() ? "Development" : "Production";

            services.AddDbContext <DBEntities>(options => options.UseMySql(Configuration.GetConnectionString(connectionString), b => b.MigrationsAssembly("DLTGuardian")));
            services.AddMvc();
        }
コード例 #2
0
    protected void Configure(IApplicationBuilder app, IHostApplicationLifetime appLifetime,
                             SharedOptions option)
    {
        var emailNotify = app.ApplicationServices.GetRequiredService <IEmailNotify>();

        appLifetime.ApplicationStarted.Register(async() =>
        {
            if (!CurrentEnv.IsDevelopment())
            {
                var message = new SendGridEmailMessage
                {
                    Content        = "<p>恭喜,网站已经运行起来了!</p>",
                    Site           = Site,
                    Subject        = "site started",
                    SendGridApiKey = option.SendGridApiKey,
                    ToEmailAddress = option.AdminEmail,
                    ToName         = option.AdminEnglishName
                };

                await emailNotify.SendAsync(message);
            }
        });

        appLifetime.ApplicationStopping.Register(async() =>
        {
            if (!CurrentEnv.IsDevelopment())
            {
                var message = new SendGridEmailMessage
                {
                    Content        = "<p>网站被停掉了,请确认是否是正常行为。</p>",
                    Site           = Site,
                    Subject        = "site stopped",
                    SendGridApiKey = option.SendGridApiKey,
                    ToEmailAddress = option.AdminEmail,
                    ToName         = option.AdminEnglishName
                };

                await emailNotify.SendAsync(message);
            }
        });

        if (CurrentEnv.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/error");
        }
    }
コード例 #3
0
    public virtual void ConfigureServices(IServiceCollection services)
    {
        services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.BasicLatin, UnicodeRanges.CjkUnifiedIdeographs));
        services.AddSingleton <IEmailNotify, SendGridEmailNotify>();
        services.AddSingleton <ILaobianLogQueue, LaobianLogQueue>();

        var dpFolder = Configuration.GetValue <string>(Constants.EnvDataProtectionKeyPath);

        Directory.CreateDirectory(dpFolder);
        services.AddDataProtection().PersistKeysToFileSystem(new DirectoryInfo(dpFolder))
        .SetApplicationName($"{Constants.ApplicationName}_{CurrentEnv.EnvironmentName}");

        services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
        .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
        {
            options.Cookie.Name        = $".LAOBIAN.AUTH.{CurrentEnv.EnvironmentName}";
            options.ExpireTimeSpan     = TimeSpan.FromDays(7);
            options.Cookie.HttpOnly    = true;
            options.ReturnUrlParameter = "returnUrl";
            options.LoginPath          = new PathString("/login");
            options.LogoutPath         = new PathString("/logout");
            options.Cookie.Domain      = CurrentEnv.IsDevelopment() ? "localhost" : ".laobian.me";
        });
    }