From f78f6970e2aa3bd6db51966fd93cffb78a0f4aa3 Mon Sep 17 00:00:00 2001 From: Argo-MacBookPro Date: Wed, 24 Oct 2018 20:31:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8A=9F=E8=83=BD=EF=BC=9A?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0web=20api=20versioning=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.Admin/Bootstrap.Admin.csproj | 3 ++- Bootstrap.Admin/Startup.cs | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Bootstrap.Admin/Bootstrap.Admin.csproj b/Bootstrap.Admin/Bootstrap.Admin.csproj index 474fc04c..9012d874 100644 --- a/Bootstrap.Admin/Bootstrap.Admin.csproj +++ b/Bootstrap.Admin/Bootstrap.Admin.csproj @@ -8,7 +8,7 @@ - Z:\src\Longbow\BootstrapAdmin\Bootstrap.Admin\Bootstrap.Admin.xml + ..\Bootstrap.Admin\Bootstrap.Admin.xml @@ -16,6 +16,7 @@ + diff --git a/Bootstrap.Admin/Startup.cs b/Bootstrap.Admin/Startup.cs index 3b8664ff..ab5ea301 100644 --- a/Bootstrap.Admin/Startup.cs +++ b/Bootstrap.Admin/Startup.cs @@ -15,6 +15,7 @@ using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Versioning; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; @@ -79,6 +80,13 @@ namespace Bootstrap.Admin JsonConvert.DefaultSettings = () => options.SerializerSettings; }).SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options => options.Cookie.Path = "/"); + services.AddApiVersioning(option => + { + option.DefaultApiVersion = new ApiVersion(1, 0); + option.ReportApiVersions = true; + option.AssumeDefaultVersionWhenUnspecified = true; + option.ApiVersionReader = ApiVersionReader.Combine(new HeaderApiVersionReader("api-version"), new QueryStringApiVersionReader("api-version")); + }); services.AddSwaggerGen(options => { options.SwaggerDoc("v1", new Info