FalconSSO/FAuth/Startup.cs

99 lines
3.5 KiB
C#
Raw Normal View History

2020-03-30 10:12:52 +08:00
using System;
using System.IO;
using System.Text.Encodings.Web;
using System.Text.Unicode;
2020-04-08 14:38:39 +08:00
using Falcon.Extend;
2020-03-30 10:12:52 +08:00
using FAuth.DataBase;
using FAuth.Extensions.Decryptor;
2020-03-30 10:12:52 +08:00
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Caching.Redis;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;
namespace FAuth
{
/// <summary>
/// Ӧ<><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
public class Startup
{
public Startup(IConfiguration configuration) {
Configuration = configuration;
}
public IConfiguration Configuration { get; }
/// <summary>
/// ע<><EFBFBD><E1B5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
/// <param name="services"><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD></param>
public void ConfigureServices(IServiceCollection services) {
//ע<><D7A2>Json<6F><6E><EFBFBD>л<EFBFBD>
2020-04-08 14:38:39 +08:00
services.AddMsJsonProvider();
2020-03-30 10:12:52 +08:00
//ע<><D7A2><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>
services.AddDbContext<FAuthDb>();
//ע<><D7A2>Redis
var rop = this.Configuration.GetSection("Redis").Get<RedisCacheOptions>();
2020-04-08 14:38:39 +08:00
services.AddRedis(rop);
2020-03-30 10:12:52 +08:00
//ע<><D7A2>MVC
services.AddControllersWithViews()
.AddJsonOptions(option => {
option.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All);
option.JsonSerializerOptions.PropertyNamingPolicy = null;
});
//ע<><D7A2>Swagger
services.AddSwaggerGen(c => {
c.SwaggerDoc("V1",new OpenApiInfo {
Title = "<22>ӿ<EFBFBD><D3BF>ĵ<EFBFBD>",
Version = "1.0",
2020-03-30 16:10:51 +08:00
Description = "api",
Contact = new OpenApiContact {
Name = "Falcon",
Url = new Uri("http://39.105.71.191/Falcon/FAuth"),
},
2020-03-30 10:12:52 +08:00
});
var xmlPath = Path.Combine(AppContext.BaseDirectory,typeof(Program).Assembly.GetName().Name + ".xml");
c.IncludeXmlComments(xmlPath,true);
2020-04-08 14:38:39 +08:00
c.AddXmlEnumEnable(xmlPath);
2020-03-30 10:12:52 +08:00
});
//ע<><D7A2><EFBFBD>û<EFBFBD>Ʊ<EFBFBD><C6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
services.AddAESCrypto();
var UTDO = Configuration.GetSection("UserTicketDecryptorOption");
services.AddUserTicketDryptor(UTDO);
2020-03-30 10:12:52 +08:00
}
// 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("/Home/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();
app.UseStaticFiles();
app.UseRouting();
app.UseSwagger();
app.UseSwaggerUI(c => {
c.SwaggerEndpoint("/swagger/V1/swagger.json","<22>ӿ<EFBFBD><D3BF>ĵ<EFBFBD>");
2020-03-30 16:10:51 +08:00
c.RoutePrefix = "api";
2020-03-30 10:12:52 +08:00
});
app.UseAuthorization();
app.UseEndpoints(endpoints => {
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}