Files
contact/Startup.cs

65 lines
2.0 KiB
C#

using System;
using System.IO;
using contact.Services;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace contact
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddSingleton<MailSender>();
services.AddHttpClient("sockeye", client =>
{
client.Timeout = TimeSpan.FromSeconds(15);
});
//Antiforgery tokens on the forms are encrypted with Data Protection keys. The service account has no
//home directory, so without this the keys live only in memory and every restart breaks forms that
//visitors already have open. Set DataProtection:KeyPath on the server (systemd StateDirectory=contact).
var keyPath = Configuration["DataProtection:KeyPath"];
if (!string.IsNullOrWhiteSpace(keyPath))
{
services.AddDataProtection()
.SetApplicationName("contact")
.PersistKeysToFileSystem(new DirectoryInfo(keyPath));
}
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
}
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapRazorPages();
});
}
}
}