ant-design-blazor/site/AntDesign.Docs.Server/Startup.cs
Hao Sun bca2414491 chore: support IE and .net6 for server-side (#2119)
* modify AntDesign.Docs.Server project to support IE

* update docs project

* update _Host.cshtml

* add .net6 target framework

* Update _Host.cshtml

* update github actions

* update github actions
2021-12-06 12:31:27 +08:00

73 lines
2.3 KiB
C#

using System.Net.Http;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
#if NET5_0_OR_GREATER
using Blazor.Polyfill.Server;
#endif
namespace AntDesign.Docs.Server
{
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.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddTransient(sp => new HttpClient()
{
DefaultRequestHeaders =
{
// Use to call the github API on server side
{"User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36 Edg/81.0.416.68"}
}
});
services.AddAntDesignDocs();
#if NET5_0_OR_GREATER
services.AddBlazorPolyfill();
#endif
}
// 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("/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();
#if NET5_0_OR_GREATER
app.UseBlazorPolyfill();
#endif
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}
}
}