From 01b821c3c60d4c39bb0e36c8ed6477b7f79fbb50 Mon Sep 17 00:00:00 2001 From: feijie Date: Thu, 18 Apr 2019 10:35:22 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E9=80=82=E7=94=A8?= =?UTF-8?q?=E4=BA=8Emysql=E7=9A=84=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ImageApi/Dockerfile | 8 +++---- ImageApi/Dockerfile1.original | 24 +++++++++++++++++++ ImageApi/ImageApi.csproj | 2 +- ImageApi/Program.cs | 2 ++ .../PublishProfiles/FolderProfile.pubxml | 3 +++ .../PublishProfiles/FolderProfile1.pubxml | 22 +++++++++++++++++ ImageApi/Startup.cs | 23 +++++++----------- ImageApi/appsettings.json | 4 ++++ ImageCore/ImageOption.cs | 4 ++-- ...ageCore.Persistence.EntityFramework.csproj | 2 ++ ....cs => 20190417083731_initial.Designer.cs} | 11 ++++----- ...30_Inital.cs => 20190417083731_initial.cs} | 5 ++-- .../Migrations/ImageDbContextModelSnapshot.cs | 7 ++---- 13 files changed, 80 insertions(+), 37 deletions(-) create mode 100644 ImageApi/Dockerfile1.original create mode 100644 ImageApi/Properties/PublishProfiles/FolderProfile1.pubxml rename Persistence/ImageCore.Persistence.EntityFramework/Migrations/{20190301113830_Inital.Designer.cs => 20190417083731_initial.Designer.cs} (83%) rename Persistence/ImageCore.Persistence.EntityFramework/Migrations/{20190301113830_Inital.cs => 20190417083731_initial.cs} (92%) diff --git a/ImageApi/Dockerfile b/ImageApi/Dockerfile index c52689d..86e47b7 100644 --- a/ImageApi/Dockerfile +++ b/ImageApi/Dockerfile @@ -1,15 +1,13 @@ -#Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed. -#For more information, please see https://aka.ms/containercompat - -FROM microsoft/dotnet:2.2-aspnetcore-runtime-nanoserver-1803 AS base +FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base WORKDIR /app EXPOSE 80 -FROM microsoft/dotnet:2.2-sdk-nanoserver-1803 AS build +FROM microsoft/dotnet:2.2-sdk AS build WORKDIR /src COPY ["ImageApi/ImageApi.csproj", "ImageApi/"] COPY ["ImageApi.Core/ImageApi.Core.csproj", "ImageApi.Core/"] COPY ["ImageCore/ImageCore.csproj", "ImageCore/"] +COPY ["Persistence/ImageCore.Persistence.EntityFramework/ImageCore.Persistence.EntityFramework.csproj", "Persistence/ImageCore.Persistence.EntityFramework/"] RUN dotnet restore "ImageApi/ImageApi.csproj" COPY . . WORKDIR "/src/ImageApi" diff --git a/ImageApi/Dockerfile1.original b/ImageApi/Dockerfile1.original new file mode 100644 index 0000000..c52689d --- /dev/null +++ b/ImageApi/Dockerfile1.original @@ -0,0 +1,24 @@ +#Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed. +#For more information, please see https://aka.ms/containercompat + +FROM microsoft/dotnet:2.2-aspnetcore-runtime-nanoserver-1803 AS base +WORKDIR /app +EXPOSE 80 + +FROM microsoft/dotnet:2.2-sdk-nanoserver-1803 AS build +WORKDIR /src +COPY ["ImageApi/ImageApi.csproj", "ImageApi/"] +COPY ["ImageApi.Core/ImageApi.Core.csproj", "ImageApi.Core/"] +COPY ["ImageCore/ImageCore.csproj", "ImageCore/"] +RUN dotnet restore "ImageApi/ImageApi.csproj" +COPY . . +WORKDIR "/src/ImageApi" +RUN dotnet build "ImageApi.csproj" -c Release -o /app + +FROM build AS publish +RUN dotnet publish "ImageApi.csproj" -c Release -o /app + +FROM base AS final +WORKDIR /app +COPY --from=publish /app . +ENTRYPOINT ["dotnet", "ImageApi.dll"] \ No newline at end of file diff --git a/ImageApi/ImageApi.csproj b/ImageApi/ImageApi.csproj index bf2c7f6..84202f9 100644 --- a/ImageApi/ImageApi.csproj +++ b/ImageApi/ImageApi.csproj @@ -3,7 +3,7 @@ netcoreapp2.2 InProcess - Windows + Linux diff --git a/ImageApi/Program.cs b/ImageApi/Program.cs index a743a1f..65862ca 100644 --- a/ImageApi/Program.cs +++ b/ImageApi/Program.cs @@ -19,6 +19,8 @@ public static void Main(string[] args) public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseUrls("http://*:8089") .UseStartup(); } } diff --git a/ImageApi/Properties/PublishProfiles/FolderProfile.pubxml b/ImageApi/Properties/PublishProfiles/FolderProfile.pubxml index 2500033..031a5e7 100644 --- a/ImageApi/Properties/PublishProfiles/FolderProfile.pubxml +++ b/ImageApi/Properties/PublishProfiles/FolderProfile.pubxml @@ -15,5 +15,8 @@ 2528c869-0822-49b2-ba00-6beebc316244 D:\wwwroot\ImageService False + netcoreapp2.2 + false + <_IsPortable>true \ No newline at end of file diff --git a/ImageApi/Properties/PublishProfiles/FolderProfile1.pubxml b/ImageApi/Properties/PublishProfiles/FolderProfile1.pubxml new file mode 100644 index 0000000..444f409 --- /dev/null +++ b/ImageApi/Properties/PublishProfiles/FolderProfile1.pubxml @@ -0,0 +1,22 @@ + + + + + FileSystem + FileSystem + Release + Any CPU + + True + False + netcoreapp2.2 + 2528c869-0822-49b2-ba00-6beebc316244 + false + <_IsPortable>true + D:\wwwroot\ImageService_Demo + False + + \ No newline at end of file diff --git a/ImageApi/Startup.cs b/ImageApi/Startup.cs index fe2eacd..2866a27 100644 --- a/ImageApi/Startup.cs +++ b/ImageApi/Startup.cs @@ -22,13 +22,13 @@ public class Startup { private const string DefaultCorsPolicyName = "public"; - private readonly IConfigurationRoot _appConfiguration; + private readonly IConfiguration configuration; private readonly IHostingEnvironment _hostingEnvironment; - public Startup(IHostingEnvironment env) + public Startup(IHostingEnvironment env, IConfiguration configuration) { _hostingEnvironment = env; - _appConfiguration = env.GetAppConfiguration(); + this.configuration = configuration; } // This method gets called by the runtime. Use this method to add services to the container. @@ -39,13 +39,16 @@ public void ConfigureServices(IServiceCollection services) services.AddSingleton( new PhysicalFileProvider(Directory.GetCurrentDirectory())); services.AddSingleton(); + services.AddEntityFrameworkNpgsql(); services.AddImageService(option => { - option.Filters = new[] {".jpg", ".png", ".bmp"}; + option.Filters = new[] {".jpg", ".jpeg", ".gif", ".png", ".bmp"}; }) .UseEntityFrameworkStore(builder => { - builder.UseSqlServer("Server=localhost; Database=ImageDb; Trusted_Connection=True;"); + //builder.UseSqlServer("Server=localhost; Database=ImageDb; Trusted_Connection=True;"); + //builder.UseNpgsql(_appConfiguration.GetConnectionString("Default")); + builder.UseMySql(configuration.GetConnectionString("Mysql")); }); services.AddCors(options => { @@ -53,7 +56,7 @@ public void ConfigureServices(IServiceCollection services) { builder .WithOrigins( - _appConfiguration["CorsOrigins"] + configuration["CorsOrigins"] .Split(",", StringSplitOptions.RemoveEmptyEntries) .ToArray() ) @@ -84,12 +87,4 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env) .UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "图片资源API"); }); } } - - public static class HostingEnvironmentExtensions - { - public static IConfigurationRoot GetAppConfiguration(this IHostingEnvironment env) - { - return AppConfigurations.Get(env.ContentRootPath, env.EnvironmentName); - } - } } diff --git a/ImageApi/appsettings.json b/ImageApi/appsettings.json index 9c898f8..79ab510 100644 --- a/ImageApi/appsettings.json +++ b/ImageApi/appsettings.json @@ -1,4 +1,8 @@ { + "ConnectionStrings": { + //"Default": "Server=172.16.4.6;Port=5432;Database=ImageDb;User Id=postgres;Password=123456", + "Mysql": "Server=212.64.91.153;Port=3306;Database=ImageDb;User Id=root;Password=feijie999" + }, "Logging": { "LogLevel": { "Default": "Warning" diff --git a/ImageCore/ImageOption.cs b/ImageCore/ImageOption.cs index 3265512..1d4d3aa 100644 --- a/ImageCore/ImageOption.cs +++ b/ImageCore/ImageOption.cs @@ -12,9 +12,9 @@ public class ImageOption public string[] Filters { get; set; } = {".jpg", ".png", ".bmp"}; /// - /// 可接收文件最大的大小单位kb,默认为2MB + /// 可接收文件最大的大小单位kb,默认为5MB /// - public long MaxContentLength { get; set; } = 1024*1024 * 2; + public long MaxContentLength { get; set; } = 1024*1024 * 5; /// /// 文件存储模式,默认为分布式存储 diff --git a/Persistence/ImageCore.Persistence.EntityFramework/ImageCore.Persistence.EntityFramework.csproj b/Persistence/ImageCore.Persistence.EntityFramework/ImageCore.Persistence.EntityFramework.csproj index 12b9d5b..63b61f7 100644 --- a/Persistence/ImageCore.Persistence.EntityFramework/ImageCore.Persistence.EntityFramework.csproj +++ b/Persistence/ImageCore.Persistence.EntityFramework/ImageCore.Persistence.EntityFramework.csproj @@ -8,6 +8,8 @@ + + diff --git a/Persistence/ImageCore.Persistence.EntityFramework/Migrations/20190301113830_Inital.Designer.cs b/Persistence/ImageCore.Persistence.EntityFramework/Migrations/20190417083731_initial.Designer.cs similarity index 83% rename from Persistence/ImageCore.Persistence.EntityFramework/Migrations/20190301113830_Inital.Designer.cs rename to Persistence/ImageCore.Persistence.EntityFramework/Migrations/20190417083731_initial.Designer.cs index f011f2b..7db3b00 100644 --- a/Persistence/ImageCore.Persistence.EntityFramework/Migrations/20190301113830_Inital.Designer.cs +++ b/Persistence/ImageCore.Persistence.EntityFramework/Migrations/20190417083731_initial.Designer.cs @@ -3,23 +3,21 @@ using ImageCore.Persistence.EntityFramework; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace ImageCore.Persistence.EntityFramework.Migrations { [DbContext(typeof(ImageDbContext))] - [Migration("20190301113830_Inital")] - partial class Inital + [Migration("20190417083731_initial")] + partial class initial { protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder .HasAnnotation("ProductVersion", "2.2.2-servicing-10034") - .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasAnnotation("Relational:MaxIdentifierLength", 64); modelBuilder.Entity("ImageCore.Persistence.EntityFramework.Image", b => { @@ -52,8 +50,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.HasKey("Id"); b.HasIndex("Key") - .IsUnique() - .HasFilter("[Key] IS NOT NULL"); + .IsUnique(); b.ToTable("Images"); }); diff --git a/Persistence/ImageCore.Persistence.EntityFramework/Migrations/20190301113830_Inital.cs b/Persistence/ImageCore.Persistence.EntityFramework/Migrations/20190417083731_initial.cs similarity index 92% rename from Persistence/ImageCore.Persistence.EntityFramework/Migrations/20190301113830_Inital.cs rename to Persistence/ImageCore.Persistence.EntityFramework/Migrations/20190417083731_initial.cs index 109f587..48f532d 100644 --- a/Persistence/ImageCore.Persistence.EntityFramework/Migrations/20190301113830_Inital.cs +++ b/Persistence/ImageCore.Persistence.EntityFramework/Migrations/20190417083731_initial.cs @@ -3,7 +3,7 @@ namespace ImageCore.Persistence.EntityFramework.Migrations { - public partial class Inital : Migration + public partial class initial : Migration { protected override void Up(MigrationBuilder migrationBuilder) { @@ -32,8 +32,7 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "IX_Images_Key", table: "Images", column: "Key", - unique: true, - filter: "[Key] IS NOT NULL"); + unique: true); } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/Persistence/ImageCore.Persistence.EntityFramework/Migrations/ImageDbContextModelSnapshot.cs b/Persistence/ImageCore.Persistence.EntityFramework/Migrations/ImageDbContextModelSnapshot.cs index 19693ae..13694e2 100644 --- a/Persistence/ImageCore.Persistence.EntityFramework/Migrations/ImageDbContextModelSnapshot.cs +++ b/Persistence/ImageCore.Persistence.EntityFramework/Migrations/ImageDbContextModelSnapshot.cs @@ -3,7 +3,6 @@ using ImageCore.Persistence.EntityFramework; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace ImageCore.Persistence.EntityFramework.Migrations @@ -16,8 +15,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) #pragma warning disable 612, 618 modelBuilder .HasAnnotation("ProductVersion", "2.2.2-servicing-10034") - .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + .HasAnnotation("Relational:MaxIdentifierLength", 64); modelBuilder.Entity("ImageCore.Persistence.EntityFramework.Image", b => { @@ -50,8 +48,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); b.HasIndex("Key") - .IsUnique() - .HasFilter("[Key] IS NOT NULL"); + .IsUnique(); b.ToTable("Images"); }); From bfa5a043f8038e14445945dc193fad826ca89f1d Mon Sep 17 00:00:00 2001 From: feijie Date: Fri, 26 Apr 2019 11:27:14 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8Djpeg=E4=B8=8D=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ImageApi/Controllers/ImageController.cs | 2 +- ImageApi/ImageFileInfoExtensions.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ImageApi/Controllers/ImageController.cs b/ImageApi/Controllers/ImageController.cs index 3e89194..fa55bd5 100644 --- a/ImageApi/Controllers/ImageController.cs +++ b/ImageApi/Controllers/ImageController.cs @@ -51,7 +51,7 @@ public ImageController(IFileStore fileStore, IImageService imageService, ImageOp /// [Route("/img/{size}/t{imageType}t{yearMonth}-{id}.{format}")] [HttpGet] - [ResponseCache(Duration = 600, Location = ResponseCacheLocation.Any)] + [ResponseCache(Duration = 600, Location = ResponseCacheLocation.Client)] public async Task Index([FromServices] IImageParameterFixer parameterFixer, [FromRoute] ImageParameter parameter) { diff --git a/ImageApi/ImageFileInfoExtensions.cs b/ImageApi/ImageFileInfoExtensions.cs index 9136e2c..9dc0e7d 100644 --- a/ImageApi/ImageFileInfoExtensions.cs +++ b/ImageApi/ImageFileInfoExtensions.cs @@ -13,6 +13,7 @@ public static ImageDto ToImage(this ImageFileInfo fileInfo) switch (fileInfo.Extension) { case ".jpg": + case ".jpeg": imageFormat = ImageFormat.Jpeg; break; case ".gif": From f4bb8417405ee64d0cdd6a048bcc72e04a582f4b Mon Sep 17 00:00:00 2001 From: feijie Date: Wed, 5 Jun 2019 10:09:59 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9C=A8Linux=E4=B8=8B?= =?UTF-8?q?=E7=9A=84=E6=96=87=E4=BB=B6=E5=A4=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ImageApi.Core/ImageParameter.cs | 4 ++-- ImageApi/ImageFileInfoExtensions.cs | 2 +- ImageApi/Startup.cs | 4 ++-- ImageApi/SwaggerFileUploadFilter.cs | 5 +++-- ImageApi/appsettings.json | 3 +-- ...itial.Designer.cs => 20190426035517_initial.Designer.cs} | 6 ++++-- ...{20190417083731_initial.cs => 20190426035517_initial.cs} | 0 .../Migrations/ImageDbContextModelSnapshot.cs | 4 +++- 8 files changed, 16 insertions(+), 12 deletions(-) rename Persistence/ImageCore.Persistence.EntityFramework/Migrations/{20190417083731_initial.Designer.cs => 20190426035517_initial.Designer.cs} (89%) rename Persistence/ImageCore.Persistence.EntityFramework/Migrations/{20190417083731_initial.cs => 20190426035517_initial.cs} (100%) diff --git a/ImageApi.Core/ImageParameter.cs b/ImageApi.Core/ImageParameter.cs index 8568514..a6c5cbb 100644 --- a/ImageApi.Core/ImageParameter.cs +++ b/ImageApi.Core/ImageParameter.cs @@ -30,7 +30,7 @@ public ImageParameter GetFixed(IImageParameterFixer fixer) public string GetRelativePath() { - var folder = $"App_Data\\storage\\images\\{this.Year}\\{this.Month}\\{this.Id}\\"; + var folder = $"App_Data/storage/images/{this.Year}/{this.Month}/{this.Id}/"; if (this.ImageFormat == ImageFormat.Gif) { return folder + "Full.gif"; @@ -40,7 +40,7 @@ public string GetRelativePath() public string GetVirtualPath() { - return "~\\"+GetRelativePath(); + return "~/"+GetRelativePath(); } } } diff --git a/ImageApi/ImageFileInfoExtensions.cs b/ImageApi/ImageFileInfoExtensions.cs index 9dc0e7d..b5c4a14 100644 --- a/ImageApi/ImageFileInfoExtensions.cs +++ b/ImageApi/ImageFileInfoExtensions.cs @@ -10,7 +10,7 @@ public static class ImageFileInfoExtensions public static ImageDto ToImage(this ImageFileInfo fileInfo) { ImageFormat imageFormat; - switch (fileInfo.Extension) + switch (fileInfo.Extension.ToLower()) { case ".jpg": case ".jpeg": diff --git a/ImageApi/Startup.cs b/ImageApi/Startup.cs index 2866a27..f5aa59b 100644 --- a/ImageApi/Startup.cs +++ b/ImageApi/Startup.cs @@ -47,8 +47,8 @@ public void ConfigureServices(IServiceCollection services) .UseEntityFrameworkStore(builder => { //builder.UseSqlServer("Server=localhost; Database=ImageDb; Trusted_Connection=True;"); - //builder.UseNpgsql(_appConfiguration.GetConnectionString("Default")); - builder.UseMySql(configuration.GetConnectionString("Mysql")); + builder.UseNpgsql(configuration.GetConnectionString("Default")); + //builder.UseMySql(configuration.GetConnectionString("Mysql")); }); services.AddCors(options => { diff --git a/ImageApi/SwaggerFileUploadFilter.cs b/ImageApi/SwaggerFileUploadFilter.cs index c287c39..90006cb 100644 --- a/ImageApi/SwaggerFileUploadFilter.cs +++ b/ImageApi/SwaggerFileUploadFilter.cs @@ -20,9 +20,10 @@ public void Apply(Operation operation, OperationFilterContext context) } var fileParameters = context.ApiDescription.ActionDescriptor.Parameters - .Where(n => n.ParameterType == typeof(IFormFile)||n.BindingInfo.BindingSource == BindingSource.FormFile).ToList(); + .Where(n => n.ParameterType == typeof(IFormFile) || + (n.BindingInfo != null && n.BindingInfo.BindingSource == BindingSource.FormFile)).ToList(); - if (fileParameters.Count < 0) + if (fileParameters.Count == 0) { return; } diff --git a/ImageApi/appsettings.json b/ImageApi/appsettings.json index 79ab510..934feb0 100644 --- a/ImageApi/appsettings.json +++ b/ImageApi/appsettings.json @@ -1,7 +1,6 @@ { "ConnectionStrings": { - //"Default": "Server=172.16.4.6;Port=5432;Database=ImageDb;User Id=postgres;Password=123456", - "Mysql": "Server=212.64.91.153;Port=3306;Database=ImageDb;User Id=root;Password=feijie999" + "Default": "Server=172.16.4.6;Port=5432;Database=ImageDb;User Id=postgres;Password=123456" }, "Logging": { "LogLevel": { diff --git a/Persistence/ImageCore.Persistence.EntityFramework/Migrations/20190417083731_initial.Designer.cs b/Persistence/ImageCore.Persistence.EntityFramework/Migrations/20190426035517_initial.Designer.cs similarity index 89% rename from Persistence/ImageCore.Persistence.EntityFramework/Migrations/20190417083731_initial.Designer.cs rename to Persistence/ImageCore.Persistence.EntityFramework/Migrations/20190426035517_initial.Designer.cs index 7db3b00..ae6af73 100644 --- a/Persistence/ImageCore.Persistence.EntityFramework/Migrations/20190417083731_initial.Designer.cs +++ b/Persistence/ImageCore.Persistence.EntityFramework/Migrations/20190426035517_initial.Designer.cs @@ -5,19 +5,21 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace ImageCore.Persistence.EntityFramework.Migrations { [DbContext(typeof(ImageDbContext))] - [Migration("20190417083731_initial")] + [Migration("20190426035517_initial")] partial class initial { protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn) .HasAnnotation("ProductVersion", "2.2.2-servicing-10034") - .HasAnnotation("Relational:MaxIdentifierLength", 64); + .HasAnnotation("Relational:MaxIdentifierLength", 63); modelBuilder.Entity("ImageCore.Persistence.EntityFramework.Image", b => { diff --git a/Persistence/ImageCore.Persistence.EntityFramework/Migrations/20190417083731_initial.cs b/Persistence/ImageCore.Persistence.EntityFramework/Migrations/20190426035517_initial.cs similarity index 100% rename from Persistence/ImageCore.Persistence.EntityFramework/Migrations/20190417083731_initial.cs rename to Persistence/ImageCore.Persistence.EntityFramework/Migrations/20190426035517_initial.cs diff --git a/Persistence/ImageCore.Persistence.EntityFramework/Migrations/ImageDbContextModelSnapshot.cs b/Persistence/ImageCore.Persistence.EntityFramework/Migrations/ImageDbContextModelSnapshot.cs index 13694e2..3dfff7c 100644 --- a/Persistence/ImageCore.Persistence.EntityFramework/Migrations/ImageDbContextModelSnapshot.cs +++ b/Persistence/ImageCore.Persistence.EntityFramework/Migrations/ImageDbContextModelSnapshot.cs @@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace ImageCore.Persistence.EntityFramework.Migrations { @@ -14,8 +15,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn) .HasAnnotation("ProductVersion", "2.2.2-servicing-10034") - .HasAnnotation("Relational:MaxIdentifierLength", 64); + .HasAnnotation("Relational:MaxIdentifierLength", 63); modelBuilder.Entity("ImageCore.Persistence.EntityFramework.Image", b => { From 3bfaf899c2c55fc934c8596c78d93521bdce8dce Mon Sep 17 00:00:00 2001 From: feijie Date: Mon, 28 Oct 2019 15:43:29 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E5=9C=A8=E9=A1=B9=E7=9B=AE=E4=B8=AD?= =?UTF-8?q?=E5=8A=A0=E5=85=A5IdentityServer=E8=AE=A4=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ImageApi/Controllers/ImageController.cs | 3 +++ ImageApi/ImageApi.csproj | 3 +++ .../PublishProfiles/FolderProfile2.pubxml | 19 ++++++++++++++ ImageApi/Startup.cs | 25 +++++++++++++++++++ ImageApi/appsettings.json | 6 ++++- 5 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 ImageApi/Properties/PublishProfiles/FolderProfile2.pubxml diff --git a/ImageApi/Controllers/ImageController.cs b/ImageApi/Controllers/ImageController.cs index fa55bd5..72a42f7 100644 --- a/ImageApi/Controllers/ImageController.cs +++ b/ImageApi/Controllers/ImageController.cs @@ -7,6 +7,7 @@ using ImageCore; using ImageCore.Enums; using ImageCore.Extensions; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -93,6 +94,8 @@ public async Task Index([FromServices] IImageParameterFixer param /// 例如 /img/s80x80/t20t201902-94E0437664E3FA99C094E0437664E3FA99C0.png /// [HttpPost] + [Authorize] + [DisableRequestSizeLimit] public async Task Upload([FromFile] ImageFileInfo file, bool isTemp = false, BusinessType businessType = BusinessType.Default) { diff --git a/ImageApi/ImageApi.csproj b/ImageApi/ImageApi.csproj index 84202f9..f3bc101 100644 --- a/ImageApi/ImageApi.csproj +++ b/ImageApi/ImageApi.csproj @@ -12,9 +12,12 @@ + + + diff --git a/ImageApi/Properties/PublishProfiles/FolderProfile2.pubxml b/ImageApi/Properties/PublishProfiles/FolderProfile2.pubxml new file mode 100644 index 0000000..8b70de7 --- /dev/null +++ b/ImageApi/Properties/PublishProfiles/FolderProfile2.pubxml @@ -0,0 +1,19 @@ + + + + + FileSystem + FileSystem + Release + Any CPU + + True + False + 2528c869-0822-49b2-ba00-6beebc316244 + D:\wwwroot\ImageServer_Mysql + False + + \ No newline at end of file diff --git a/ImageApi/Startup.cs b/ImageApi/Startup.cs index f5aa59b..7c20f5d 100644 --- a/ImageApi/Startup.cs +++ b/ImageApi/Startup.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Linq; @@ -40,6 +41,20 @@ public void ConfigureServices(IServiceCollection services) new PhysicalFileProvider(Directory.GetCurrentDirectory())); services.AddSingleton(); services.AddEntityFrameworkNpgsql(); + services.AddAuthentication("Bearer") + .AddIdentityServerAuthentication(options => + { + options.Authority = configuration["AuthServer:Authority"]; + options.RequireHttpsMetadata = false; + options.ApiName = configuration["AuthServer:ApiName"]; + //options.InboundJwtClaimTypeMap["sub"] = AbpClaimTypes.UserId; + //options.InboundJwtClaimTypeMap["role"] = AbpClaimTypes.Role; + //options.InboundJwtClaimTypeMap["email"] = AbpClaimTypes.Email; + //options.InboundJwtClaimTypeMap["email_verified"] = AbpClaimTypes.EmailVerified; + //options.InboundJwtClaimTypeMap["phone_number"] = AbpClaimTypes.PhoneNumber; + //options.InboundJwtClaimTypeMap["phone_number_verified"] = AbpClaimTypes.PhoneNumberVerified; + //options.InboundJwtClaimTypeMap["name"] = AbpClaimTypes.UserName; + }); services.AddImageService(option => { option.Filters = new[] {".jpg", ".jpeg", ".gif", ".png", ".bmp"}; @@ -71,6 +86,15 @@ public void ConfigureServices(IServiceCollection services) c.SwaggerDoc("v1", new Info {Title = "图片资源API", Version = "v1"}); c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "ImageApi.xml")); c.OperationFilter(); + c.AddSecurityDefinition("bearerAuth", new ApiKeyScheme() + { + Description = "JWT Authorization header using the bearer scheme. Example: \"Authorization: Bearer {token}\"", + Name = "Authorization", + In = "header", + Type = "apiKey" + }); + var security = new Dictionary> { { "bearerAuth", new string[] { } }, }; + c.AddSecurityRequirement(security); }); } @@ -82,6 +106,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env) app.UseDeveloperExceptionPage(); } app.UseCors(DefaultCorsPolicyName); + app.UseAuthentication(); app.UseMvcWithDefaultRoute(); app.UseSwagger() .UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "图片资源API"); }); diff --git a/ImageApi/appsettings.json b/ImageApi/appsettings.json index 934feb0..3d03031 100644 --- a/ImageApi/appsettings.json +++ b/ImageApi/appsettings.json @@ -1,6 +1,10 @@ { "ConnectionStrings": { - "Default": "Server=172.16.4.6;Port=5432;Database=ImageDb;User Id=postgres;Password=123456" + "Default": "host=6.6.6.6;port=5432;database=image;userid=postgres;pwd=123123;" + }, + "AuthServer": { + "Authority": "http://localhost:44305/", + "ApiName": "Image" }, "Logging": { "LogLevel": { From f066954579b903162970ca116d970d7bbd937bd6 Mon Sep 17 00:00:00 2001 From: feijie Date: Mon, 28 Oct 2019 19:25:05 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E5=88=B0dotnetcore3.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ImageApi.Core/ImageApi.Core.csproj | 2 +- ImageApi.Core/WebFileInfo.cs | 37 +++++-------- ImageApi/Controllers/ImageController.cs | 3 +- ImageApi/ImageApi.csproj | 8 +-- ImageApi/ImageFileInfoExtensions.cs | 2 +- .../PublishProfiles/Datum_Cloud.pubxml | 21 +++++++ ImageApi/Startup.cs | 55 ++++++++++++------- ImageApi/SwaggerFileUploadFilter.cs | 18 +++--- ImageApi/appsettings.json | 2 +- ImageCore/FileInfo.cs | 3 +- ImageCore/ImageCore.csproj | 2 +- ImageCore/ImageService.cs | 40 ++++++-------- ...ageCore.Persistence.EntityFramework.csproj | 2 +- 13 files changed, 108 insertions(+), 87 deletions(-) create mode 100644 ImageApi/Properties/PublishProfiles/Datum_Cloud.pubxml diff --git a/ImageApi.Core/ImageApi.Core.csproj b/ImageApi.Core/ImageApi.Core.csproj index 611b56b..9a3f839 100644 --- a/ImageApi.Core/ImageApi.Core.csproj +++ b/ImageApi.Core/ImageApi.Core.csproj @@ -1,7 +1,7 @@ - netcoreapp2.2 + netcoreapp3.0 diff --git a/ImageApi.Core/WebFileInfo.cs b/ImageApi.Core/WebFileInfo.cs index 3677995..2b1e512 100644 --- a/ImageApi.Core/WebFileInfo.cs +++ b/ImageApi.Core/WebFileInfo.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Text; +using System.Text.Json.Serialization; using System.Threading.Tasks; using ImageCore; using Microsoft.AspNetCore.Http; @@ -16,37 +17,29 @@ protected override Task CopyToAsync(Stream stream) return File.CopyToAsync(stream); } - private IFormFile _file; - public IFormFile File + public IFormFile File { get; set; } + + public void Fix() { - get => _file; - set - { - if (value != null) - { - this._file = value; - this.FileType = this._file.ContentType; - this.Length = this._file.Length; - this.Extension = this._file.FileName.Substring(_file.FileName.LastIndexOf('.')); - if (string.IsNullOrEmpty(this.FileName)) - this.FileName = this._file.FileName; - } - } + this.FileType = this.File.ContentType; + this.Length = this.File.Length; + this.Extension = this.File.FileName.Substring(File.FileName.LastIndexOf('.')); + if (string.IsNullOrEmpty(this.FileName)) + this.FileName = this.File.FileName; } private byte[] _fileBytes; + [JsonIgnore] public byte[] FileBytes { get { - if (_fileBytes != null || _file == null) return _fileBytes; - using (var fileStream = _file.OpenReadStream()) - { - _fileBytes = new byte[_file.Length]; - fileStream.Read(_fileBytes, 0, _fileBytes.Length); - return _fileBytes; - } + if (_fileBytes != null || File == null) return _fileBytes; + using var fileStream = File.OpenReadStream(); + _fileBytes = new byte[File.Length]; + fileStream.Read(_fileBytes, 0, _fileBytes.Length); + return _fileBytes; } set => _fileBytes = value; } diff --git a/ImageApi/Controllers/ImageController.cs b/ImageApi/Controllers/ImageController.cs index 72a42f7..96098e1 100644 --- a/ImageApi/Controllers/ImageController.cs +++ b/ImageApi/Controllers/ImageController.cs @@ -96,9 +96,10 @@ public async Task Index([FromServices] IImageParameterFixer param [HttpPost] [Authorize] [DisableRequestSizeLimit] - public async Task Upload([FromFile] ImageFileInfo file, bool isTemp = false, + public async Task Upload([FromForm] ImageFileInfo file, bool isTemp = false, BusinessType businessType = BusinessType.Default) { + file.Fix(); file.Validate(_imageOption); var image = file.ToImage(); var imageKey = await _fileStore.SaveAsync(image, isTemp); diff --git a/ImageApi/ImageApi.csproj b/ImageApi/ImageApi.csproj index f3bc101..4e01588 100644 --- a/ImageApi/ImageApi.csproj +++ b/ImageApi/ImageApi.csproj @@ -1,7 +1,7 @@ - + - netcoreapp2.2 + netcoreapp3.0 InProcess Linux @@ -13,15 +13,13 @@ - - - + diff --git a/ImageApi/ImageFileInfoExtensions.cs b/ImageApi/ImageFileInfoExtensions.cs index b5c4a14..d9a64ef 100644 --- a/ImageApi/ImageFileInfoExtensions.cs +++ b/ImageApi/ImageFileInfoExtensions.cs @@ -32,7 +32,7 @@ public static ImageDto ToImage(this ImageFileInfo fileInfo) var image = new ImageDto() { Format = imageFormat, - Length = fileInfo.Length, + Length = fileInfo.Length.Value, Bytes = fileInfo.FileBytes, CreateTime = DateTime.Now, Name = fileInfo.FileName, diff --git a/ImageApi/Properties/PublishProfiles/Datum_Cloud.pubxml b/ImageApi/Properties/PublishProfiles/Datum_Cloud.pubxml new file mode 100644 index 0000000..f29c4df --- /dev/null +++ b/ImageApi/Properties/PublishProfiles/Datum_Cloud.pubxml @@ -0,0 +1,21 @@ + + + + + FileSystem + FileSystem + Release + Any CPU + + True + False + 2528c869-0822-49b2-ba00-6beebc316244 + D:\wwwroot\DatumCloud_Dev\Image + False + netcoreapp3.0 + false + + \ No newline at end of file diff --git a/ImageApi/Startup.cs b/ImageApi/Startup.cs index 7c20f5d..b2046a5 100644 --- a/ImageApi/Startup.cs +++ b/ImageApi/Startup.cs @@ -15,6 +15,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; +using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.Swagger; namespace ImageApi @@ -36,11 +37,13 @@ public Startup(IHostingEnvironment env, IConfiguration configuration) // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { - services.AddMvc(); + services.AddMvcCore() + .AddApiExplorer(); services.AddSingleton( new PhysicalFileProvider(Directory.GetCurrentDirectory())); services.AddSingleton(); services.AddEntityFrameworkNpgsql(); + services.AddAuthorization(); services.AddAuthentication("Bearer") .AddIdentityServerAuthentication(options => { @@ -70,44 +73,54 @@ public void ConfigureServices(IServiceCollection services) options.AddPolicy(DefaultCorsPolicyName, builder => { builder - .WithOrigins( - configuration["CorsOrigins"] - .Split(",", StringSplitOptions.RemoveEmptyEntries) - .ToArray() - ) - .SetIsOriginAllowedToAllowWildcardSubdomains() + //.WithOrigins( + // configuration["CorsOrigins"] + // .Split(",", StringSplitOptions.RemoveEmptyEntries) + // .ToArray() + //) + .AllowAnyOrigin() + //.SetIsOriginAllowedToAllowWildcardSubdomains() .AllowAnyHeader() - .AllowAnyMethod() - .AllowCredentials(); + .AllowAnyMethod(); + //.AllowCredentials(); }); }); services.AddSwaggerGen(c => { - c.SwaggerDoc("v1", new Info {Title = "图片资源API", Version = "v1"}); + c.SwaggerDoc("v1", new OpenApiInfo { Title = "图片资源API", Version = "v1"}); c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "ImageApi.xml")); c.OperationFilter(); - c.AddSecurityDefinition("bearerAuth", new ApiKeyScheme() + c.AddSecurityDefinition("bearerAuth", new OpenApiSecurityScheme() { Description = "JWT Authorization header using the bearer scheme. Example: \"Authorization: Bearer {token}\"", Name = "Authorization", - In = "header", - Type = "apiKey" + In = ParameterLocation.Header, + Type = SecuritySchemeType.ApiKey }); - var security = new Dictionary> { { "bearerAuth", new string[] { } }, }; - c.AddSecurityRequirement(security); + var apiSecurityRequirement = new OpenApiSecurityRequirement + { + { + new OpenApiSecurityScheme + { + Reference = new OpenApiReference + {Type = ReferenceType.SecurityScheme, Id = "bearerAuth"} + }, + new List() + } + }; + c.AddSecurityRequirement(apiSecurityRequirement); }); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app) { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } app.UseCors(DefaultCorsPolicyName); + app.UseRouting(); app.UseAuthentication(); - app.UseMvcWithDefaultRoute(); + app.UseAuthorization(); + app.UseRouting() + .UseEndpoints(endpoints => endpoints.MapDefaultControllerRoute()); app.UseSwagger() .UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "图片资源API"); }); } diff --git a/ImageApi/SwaggerFileUploadFilter.cs b/ImageApi/SwaggerFileUploadFilter.cs index 90006cb..a6bd881 100644 --- a/ImageApi/SwaggerFileUploadFilter.cs +++ b/ImageApi/SwaggerFileUploadFilter.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.ModelBinding; +using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.Swagger; using Swashbuckle.AspNetCore.SwaggerGen; @@ -11,7 +12,7 @@ namespace ImageApi { public class SwaggerFileUploadFilter : IOperationFilter { - public void Apply(Operation operation, OperationFilterContext context) + public void Apply(OpenApiOperation operation, OperationFilterContext context) { if (!context.ApiDescription.HttpMethod.Equals("POST", StringComparison.OrdinalIgnoreCase) && !context.ApiDescription.HttpMethod.Equals("PUT", StringComparison.OrdinalIgnoreCase)) @@ -27,20 +28,19 @@ public void Apply(Operation operation, OperationFilterContext context) { return; } - - operation.Consumes.Add("multipart/form-data"); - foreach (var fileParameter in fileParameters) { - var parameter = operation.Parameters.Single(n => n.Name == fileParameter.Name); + var parameter = operation.Parameters.FirstOrDefault(n => n.Name == fileParameter.Name); + if (parameter == null) + { + continue; + } operation.Parameters.Remove(parameter); - operation.Parameters.Add(new NonBodyParameter + operation.Parameters.Add(new OpenApiParameter() { Name = parameter.Name, - In = "formData", Description = parameter.Description, - Required = parameter.Required, - Type = "file" + Required = parameter.Required }); } } diff --git a/ImageApi/appsettings.json b/ImageApi/appsettings.json index 3d03031..b64639e 100644 --- a/ImageApi/appsettings.json +++ b/ImageApi/appsettings.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "Default": "host=6.6.6.6;port=5432;database=image;userid=postgres;pwd=123123;" + "Default": "host=6.6.6.102;port=5432;database=datum_cloud_image;userid=postgres;pwd=GrRhv1OT7gJb;" }, "AuthServer": { "Authority": "http://localhost:44305/", diff --git a/ImageCore/FileInfo.cs b/ImageCore/FileInfo.cs index 6eb9896..e079998 100644 --- a/ImageCore/FileInfo.cs +++ b/ImageCore/FileInfo.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Linq; +using System.Text.Json.Serialization; using System.Threading.Tasks; namespace ImageCore @@ -8,7 +9,7 @@ namespace ImageCore public abstract class FileInfo { public string FileName { get; set; } - public long Length { get; set; } + public long? Length { get; set; } public string Extension { get; set; } public string FileType { get; set; } diff --git a/ImageCore/ImageCore.csproj b/ImageCore/ImageCore.csproj index 48b6c2e..1700107 100644 --- a/ImageCore/ImageCore.csproj +++ b/ImageCore/ImageCore.csproj @@ -1,7 +1,7 @@ - netcoreapp2.2 + netcoreapp3.0 diff --git a/ImageCore/ImageService.cs b/ImageCore/ImageService.cs index 0495354..b5301ca 100644 --- a/ImageCore/ImageService.cs +++ b/ImageCore/ImageService.cs @@ -16,33 +16,27 @@ public class ImageService : IImageService { public byte[] ImageCast(byte[] bytes,ImageSize imageSize, ImageFormat format) { - using (var image = Image.Load(bytes)) - { - image.Mutate(x => x - .Resize(imageSize.GetSize())); - using (var stream = new MemoryStream()) - { - var encoder = - image.GetConfiguration().ImageFormatsManager.FindEncoder(format.GetFormat()); - image.Save(stream, encoder); - stream.Seek(0, SeekOrigin.Begin); - var result = new byte[stream.Length]; - stream.Read(result, 0, result.Length); - return result; - } - } + using var image = Image.Load(bytes); + image.Mutate(x => x + .Resize(imageSize.GetSize())); + using var stream = new MemoryStream(); + var encoder = + image.GetConfiguration().ImageFormatsManager.FindEncoder(format.GetFormat()); + image.Save(stream, encoder); + stream.Seek(0, SeekOrigin.Begin); + var result = new byte[stream.Length]; + stream.Read(result, 0, result.Length); + return result; } public void ImageCastAndSaveToFile(byte[] bytes, ImageSize imageSize, ImageFormat format, string physicalPath) { - using (var image = Image.Load(bytes)) - { - var encoder = - image.GetConfiguration().ImageFormatsManager.FindEncoder(format.GetFormat()); - image.Mutate(x => x - .Resize(imageSize.GetSize())); - image.Save(physicalPath, encoder); - } + using var image = Image.Load(bytes); + var encoder = + image.GetConfiguration().ImageFormatsManager.FindEncoder(format.GetFormat()); + image.Mutate(x => x + .Resize(imageSize.GetSize())); + image.Save(physicalPath, encoder); } public string GenerateKey(BusinessType type, Guid id, ImageFormat format) diff --git a/Persistence/ImageCore.Persistence.EntityFramework/ImageCore.Persistence.EntityFramework.csproj b/Persistence/ImageCore.Persistence.EntityFramework/ImageCore.Persistence.EntityFramework.csproj index 63b61f7..3d81ee2 100644 --- a/Persistence/ImageCore.Persistence.EntityFramework/ImageCore.Persistence.EntityFramework.csproj +++ b/Persistence/ImageCore.Persistence.EntityFramework/ImageCore.Persistence.EntityFramework.csproj @@ -1,7 +1,7 @@ - netcoreapp2.2 + netcoreapp3.0 From c586e31fb1c1790a5f6c12ef2e174a627c3043b6 Mon Sep 17 00:00:00 2001 From: feijie Date: Tue, 29 Oct 2019 10:44:38 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=A4=E8=AF=81bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ImageApi/Program.cs | 1 - ImageApi/Startup.cs | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/ImageApi/Program.cs b/ImageApi/Program.cs index 65862ca..5fe435c 100644 --- a/ImageApi/Program.cs +++ b/ImageApi/Program.cs @@ -20,7 +20,6 @@ public static void Main(string[] args) public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseContentRoot(Directory.GetCurrentDirectory()) - .UseUrls("http://*:8089") .UseStartup(); } } diff --git a/ImageApi/Startup.cs b/ImageApi/Startup.cs index b2046a5..5602de4 100644 --- a/ImageApi/Startup.cs +++ b/ImageApi/Startup.cs @@ -79,10 +79,10 @@ public void ConfigureServices(IServiceCollection services) // .ToArray() //) .AllowAnyOrigin() - //.SetIsOriginAllowedToAllowWildcardSubdomains() + .SetIsOriginAllowedToAllowWildcardSubdomains() .AllowAnyHeader() .AllowAnyMethod(); - //.AllowCredentials(); + //.AllowCredentials(); }); }); services.AddSwaggerGen(c => @@ -118,8 +118,7 @@ public void Configure(IApplicationBuilder app) app.UseCors(DefaultCorsPolicyName); app.UseRouting(); app.UseAuthentication(); - app.UseAuthorization(); - app.UseRouting() + app.UseAuthorization() .UseEndpoints(endpoints => endpoints.MapDefaultControllerRoute()); app.UseSwagger() .UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "图片资源API"); });