From e0639f4d81d0094b6b369e03fa01fa9f789ebd91 Mon Sep 17 00:00:00 2001 From: bicijinlian Date: Sun, 23 Jun 2024 13:09:23 +0800 Subject: [PATCH] =?UTF-8?q?feat(all):=E6=B7=BB=E5=8A=A0=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- Docs/项目说明.md | 22 +++++++++---------- .../发布到文件夹-调试版.pubxml | 21 ++++++++++++++++++ .../PublishProfiles/发布到文件夹.pubxml | 21 ++++++++++++++++++ .../发布到文件夹-调试版.pubxml | 21 ++++++++++++++++++ .../PublishProfiles/发布到文件夹.pubxml | 21 ++++++++++++++++++ .../发布到文件夹-调试版.pubxml | 21 ++++++++++++++++++ .../PublishProfiles/发布到文件夹.pubxml | 21 ++++++++++++++++++ .../发布到文件夹-调试版.pubxml | 21 ++++++++++++++++++ .../PublishProfiles/发布到文件夹.pubxml | 21 ++++++++++++++++++ .../发布到文件夹-调试版.pubxml | 21 ++++++++++++++++++ .../PublishProfiles/发布到文件夹.pubxml | 21 ++++++++++++++++++ LaunchUrlStudy.SubSite5/Program.cs | 4 ++-- .../发布到文件夹-调试版.pubxml | 21 ++++++++++++++++++ .../PublishProfiles/发布到文件夹.pubxml | 21 ++++++++++++++++++ .../Properties/launchSettings.json | 4 ++-- .../发布到文件夹-调试版.pubxml | 21 ++++++++++++++++++ .../PublishProfiles/发布到文件夹.pubxml | 21 ++++++++++++++++++ .../发布到文件夹-调试版.pubxml | 21 ++++++++++++++++++ .../PublishProfiles/发布到文件夹.pubxml | 21 ++++++++++++++++++ .../发布到文件夹-调试版.pubxml | 21 ++++++++++++++++++ .../PublishProfiles/发布到文件夹.pubxml | 21 ++++++++++++++++++ LaunchUrlStudy.sln | 10 ++++----- 23 files changed, 399 insertions(+), 21 deletions(-) create mode 100644 LaunchUrlStudy.DefaultApi/Properties/PublishProfiles/发布到文件夹-调试版.pubxml create mode 100644 LaunchUrlStudy.DefaultApi/Properties/PublishProfiles/发布到文件夹.pubxml create mode 100644 LaunchUrlStudy.SubSite1/Properties/PublishProfiles/发布到文件夹-调试版.pubxml create mode 100644 LaunchUrlStudy.SubSite1/Properties/PublishProfiles/发布到文件夹.pubxml create mode 100644 LaunchUrlStudy.SubSite2/Properties/PublishProfiles/发布到文件夹-调试版.pubxml create mode 100644 LaunchUrlStudy.SubSite2/Properties/PublishProfiles/发布到文件夹.pubxml create mode 100644 LaunchUrlStudy.SubSite3/Properties/PublishProfiles/发布到文件夹-调试版.pubxml create mode 100644 LaunchUrlStudy.SubSite3/Properties/PublishProfiles/发布到文件夹.pubxml create mode 100644 LaunchUrlStudy.SubSite4/Properties/PublishProfiles/发布到文件夹-调试版.pubxml create mode 100644 LaunchUrlStudy.SubSite4/Properties/PublishProfiles/发布到文件夹.pubxml create mode 100644 LaunchUrlStudy.SubSite5/Properties/PublishProfiles/发布到文件夹-调试版.pubxml create mode 100644 LaunchUrlStudy.SubSite5/Properties/PublishProfiles/发布到文件夹.pubxml create mode 100644 LaunchUrlStudy.SubSite6/Properties/PublishProfiles/发布到文件夹-调试版.pubxml create mode 100644 LaunchUrlStudy.SubSite6/Properties/PublishProfiles/发布到文件夹.pubxml create mode 100644 LaunchUrlStudy.SubSite7/Properties/PublishProfiles/发布到文件夹-调试版.pubxml create mode 100644 LaunchUrlStudy.SubSite7/Properties/PublishProfiles/发布到文件夹.pubxml create mode 100644 LaunchUrlStudy.SubSite8/Properties/PublishProfiles/发布到文件夹-调试版.pubxml create mode 100644 LaunchUrlStudy.SubSite8/Properties/PublishProfiles/发布到文件夹.pubxml diff --git a/.gitignore b/.gitignore index 08bd5dc..8335e4b 100644 --- a/.gitignore +++ b/.gitignore @@ -226,7 +226,7 @@ publish/ *.azurePubxml # Note: Comment the next line if you want to checkin your web deploy settings, # but database connection strings (with potential passwords) will be unencrypted -*.pubxml +# *.pubxml *.publishproj # Microsoft Azure Web App publish settings. Comment the next line if you want to diff --git a/Docs/项目说明.md b/Docs/项目说明.md index 468e607..92aa40a 100644 --- a/Docs/项目说明.md +++ b/Docs/项目说明.md @@ -154,7 +154,7 @@ //配置启动地址(支持子站点):自定义中间件+重定向 app.Use(async (context, next) => { - if (context.Request.Path == "/") + if (context.Request.Path == "/" || context.Request.Path == "") { context.Response.Redirect($"{context.Request.PathBase}/swagger/Index.html"); } @@ -170,7 +170,7 @@ } ``` -+ 第三方中间件:`Swagger中间件` 不支持子站点 ++ 第三方中间件:`Swagger中间件` 子站点时,末尾必须是/才能正确 ```csharp namespace LaunchUrlStudy.SubSite5 @@ -245,21 +245,21 @@ public static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); - + // Add services to the container. - + builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); - + var app = builder.Build(); - + app.UseSwagger(); app.UseSwaggerUI(); - + app.UseAuthorization(); app.MapControllers(); - + // 配置启动地址(支持子站点):静态文件服务器默认页 // 只能是wwwroot里的静态真实文件,不能是"swagger/index.html"(因为它是㠌入的资源文件,不在wwwroot中) app.UseDefaultFiles(new DefaultFilesOptions() @@ -274,7 +274,7 @@ } }); app.UseStaticFiles(); - + app.Run(); } } @@ -286,7 +286,7 @@ 这需要事先知道子站点的值,不灵活。环境变量可以在Docker中使用,配置文件就太不灵活了。 -+ 部署配置 ++ 部署配置:不推荐 在部署 ASP.NET 6 Web API时,配置服务器或反向代理服务器(如Nginx或Apache)来处理默认请求。例如,在Nginx配置中设置默认页面: ```lua @@ -304,7 +304,7 @@ } ``` -+ 使用URL重写规则 不推荐 ++ 使用URL重写规则:不推荐 在使用IIS或Nginx等软件代理时,可以设置URL重写规则。因为需要引入组件和配置规则,相对来说太麻烦,不推荐使用。 总结: diff --git a/LaunchUrlStudy.DefaultApi/Properties/PublishProfiles/发布到文件夹-调试版.pubxml b/LaunchUrlStudy.DefaultApi/Properties/PublishProfiles/发布到文件夹-调试版.pubxml new file mode 100644 index 0000000..3ef6863 --- /dev/null +++ b/LaunchUrlStudy.DefaultApi/Properties/PublishProfiles/发布到文件夹-调试版.pubxml @@ -0,0 +1,21 @@ + + + + + true + false + true + Debug + Any CPU + FileSystem + ..\Publish\DefaultApi-Debug + FileSystem + <_TargetId>Folder + + net8.0 + 97FB68D0-5944-4624-83A8-BAFE628300DA + false + + \ No newline at end of file diff --git a/LaunchUrlStudy.DefaultApi/Properties/PublishProfiles/发布到文件夹.pubxml b/LaunchUrlStudy.DefaultApi/Properties/PublishProfiles/发布到文件夹.pubxml new file mode 100644 index 0000000..d5f2742 --- /dev/null +++ b/LaunchUrlStudy.DefaultApi/Properties/PublishProfiles/发布到文件夹.pubxml @@ -0,0 +1,21 @@ + + + + + true + false + true + Release + Any CPU + FileSystem + ..\Publish\DefaultApi + FileSystem + <_TargetId>Folder + + net8.0 + 97FB68D0-5944-4624-83A8-BAFE628300DA + false + + \ No newline at end of file diff --git a/LaunchUrlStudy.SubSite1/Properties/PublishProfiles/发布到文件夹-调试版.pubxml b/LaunchUrlStudy.SubSite1/Properties/PublishProfiles/发布到文件夹-调试版.pubxml new file mode 100644 index 0000000..64e925c --- /dev/null +++ b/LaunchUrlStudy.SubSite1/Properties/PublishProfiles/发布到文件夹-调试版.pubxml @@ -0,0 +1,21 @@ + + + + + true + false + true + Debug + Any CPU + FileSystem + ..\Publish\SubSite1-Debug + FileSystem + <_TargetId>Folder + + net8.0 + BDE104AC-A2D2-411D-A171-8387CA80E4A8 + false + + \ No newline at end of file diff --git a/LaunchUrlStudy.SubSite1/Properties/PublishProfiles/发布到文件夹.pubxml b/LaunchUrlStudy.SubSite1/Properties/PublishProfiles/发布到文件夹.pubxml new file mode 100644 index 0000000..3be250d --- /dev/null +++ b/LaunchUrlStudy.SubSite1/Properties/PublishProfiles/发布到文件夹.pubxml @@ -0,0 +1,21 @@ + + + + + true + false + true + Release + Any CPU + FileSystem + ..\Publish\SubSite1 + FileSystem + <_TargetId>Folder + + net8.0 + BDE104AC-A2D2-411D-A171-8387CA80E4A8 + false + + \ No newline at end of file diff --git a/LaunchUrlStudy.SubSite2/Properties/PublishProfiles/发布到文件夹-调试版.pubxml b/LaunchUrlStudy.SubSite2/Properties/PublishProfiles/发布到文件夹-调试版.pubxml new file mode 100644 index 0000000..4a7cdba --- /dev/null +++ b/LaunchUrlStudy.SubSite2/Properties/PublishProfiles/发布到文件夹-调试版.pubxml @@ -0,0 +1,21 @@ + + + + + true + false + true + Debug + Any CPU + FileSystem + ..\Publish\SubSite2-Debug + FileSystem + <_TargetId>Folder + + net8.0 + 8E365EB7-31BB-484B-B57F-E929E834AE5E + false + + \ No newline at end of file diff --git a/LaunchUrlStudy.SubSite2/Properties/PublishProfiles/发布到文件夹.pubxml b/LaunchUrlStudy.SubSite2/Properties/PublishProfiles/发布到文件夹.pubxml new file mode 100644 index 0000000..35bcae8 --- /dev/null +++ b/LaunchUrlStudy.SubSite2/Properties/PublishProfiles/发布到文件夹.pubxml @@ -0,0 +1,21 @@ + + + + + true + false + true + Release + Any CPU + FileSystem + ..\Publish\SubSite2 + FileSystem + <_TargetId>Folder + + net8.0 + 8E365EB7-31BB-484B-B57F-E929E834AE5E + false + + \ No newline at end of file diff --git a/LaunchUrlStudy.SubSite3/Properties/PublishProfiles/发布到文件夹-调试版.pubxml b/LaunchUrlStudy.SubSite3/Properties/PublishProfiles/发布到文件夹-调试版.pubxml new file mode 100644 index 0000000..e0d45a4 --- /dev/null +++ b/LaunchUrlStudy.SubSite3/Properties/PublishProfiles/发布到文件夹-调试版.pubxml @@ -0,0 +1,21 @@ + + + + + true + false + true + Debug + Any CPU + FileSystem + ..\Publish\SubSite3-Debug + FileSystem + <_TargetId>Folder + + net8.0 + 7BDFEC9E-2818-4BF0-BEDD-120BF6965D00 + false + + \ No newline at end of file diff --git a/LaunchUrlStudy.SubSite3/Properties/PublishProfiles/发布到文件夹.pubxml b/LaunchUrlStudy.SubSite3/Properties/PublishProfiles/发布到文件夹.pubxml new file mode 100644 index 0000000..34cc481 --- /dev/null +++ b/LaunchUrlStudy.SubSite3/Properties/PublishProfiles/发布到文件夹.pubxml @@ -0,0 +1,21 @@ + + + + + true + false + true + Release + Any CPU + FileSystem + ..\Publish\SubSite3 + FileSystem + <_TargetId>Folder + + net8.0 + 7BDFEC9E-2818-4BF0-BEDD-120BF6965D00 + false + + \ No newline at end of file diff --git a/LaunchUrlStudy.SubSite4/Properties/PublishProfiles/发布到文件夹-调试版.pubxml b/LaunchUrlStudy.SubSite4/Properties/PublishProfiles/发布到文件夹-调试版.pubxml new file mode 100644 index 0000000..cecd8ab --- /dev/null +++ b/LaunchUrlStudy.SubSite4/Properties/PublishProfiles/发布到文件夹-调试版.pubxml @@ -0,0 +1,21 @@ + + + + + true + false + true + Debug + Any CPU + FileSystem + ..\Publish\SubSite3-Debug + FileSystem + <_TargetId>Folder + + net8.0 + 21B0DDA7-982D-417D-8D99-22D799DAF067 + false + + \ No newline at end of file diff --git a/LaunchUrlStudy.SubSite4/Properties/PublishProfiles/发布到文件夹.pubxml b/LaunchUrlStudy.SubSite4/Properties/PublishProfiles/发布到文件夹.pubxml new file mode 100644 index 0000000..df14fd1 --- /dev/null +++ b/LaunchUrlStudy.SubSite4/Properties/PublishProfiles/发布到文件夹.pubxml @@ -0,0 +1,21 @@ + + + + + true + false + true + Release + Any CPU + FileSystem + ..\Publish\SubSite3 + FileSystem + <_TargetId>Folder + + net8.0 + 21B0DDA7-982D-417D-8D99-22D799DAF067 + false + + \ No newline at end of file diff --git a/LaunchUrlStudy.SubSite5/Program.cs b/LaunchUrlStudy.SubSite5/Program.cs index 7615848..c9f548f 100644 --- a/LaunchUrlStudy.SubSite5/Program.cs +++ b/LaunchUrlStudy.SubSite5/Program.cs @@ -17,8 +17,8 @@ namespace LaunchUrlStudy.SubSite5 // 配置启动地址(不支持子站点):设置Swagger中间件 app.UseSwaggerUI(config => { - config.SwaggerEndpoint("swagger/v1/swagger.json", "My API V1"); - config.RoutePrefix = string.Empty; + config.SwaggerEndpoint("./swagger/v1/swagger.json", "My API V1"); + config.RoutePrefix = ""; }); app.UseAuthorization(); diff --git a/LaunchUrlStudy.SubSite5/Properties/PublishProfiles/发布到文件夹-调试版.pubxml b/LaunchUrlStudy.SubSite5/Properties/PublishProfiles/发布到文件夹-调试版.pubxml new file mode 100644 index 0000000..2cb783b --- /dev/null +++ b/LaunchUrlStudy.SubSite5/Properties/PublishProfiles/发布到文件夹-调试版.pubxml @@ -0,0 +1,21 @@ + + + + + true + false + true + Debug + Any CPU + FileSystem + ..\Publish\SubSite-Debug + FileSystem + <_TargetId>Folder + + net8.0 + a37f6030-d2fb-4fcc-b796-83f66bacf991 + false + + \ No newline at end of file diff --git a/LaunchUrlStudy.SubSite5/Properties/PublishProfiles/发布到文件夹.pubxml b/LaunchUrlStudy.SubSite5/Properties/PublishProfiles/发布到文件夹.pubxml new file mode 100644 index 0000000..5d59d54 --- /dev/null +++ b/LaunchUrlStudy.SubSite5/Properties/PublishProfiles/发布到文件夹.pubxml @@ -0,0 +1,21 @@ + + + + + true + false + true + Release + Any CPU + FileSystem + ..\Publish\SubSite5 + FileSystem + <_TargetId>Folder + + net8.0 + a37f6030-d2fb-4fcc-b796-83f66bacf991 + false + + \ No newline at end of file diff --git a/LaunchUrlStudy.SubSite5/Properties/launchSettings.json b/LaunchUrlStudy.SubSite5/Properties/launchSettings.json index 2687c47..789464f 100644 --- a/LaunchUrlStudy.SubSite5/Properties/launchSettings.json +++ b/LaunchUrlStudy.SubSite5/Properties/launchSettings.json @@ -13,7 +13,7 @@ "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, - "launchUrl": "/", + "launchUrl": "", "applicationUrl": "http://localhost:5169", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" @@ -22,7 +22,7 @@ "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, - "launchUrl": "/", + "launchUrl": "", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } diff --git a/LaunchUrlStudy.SubSite6/Properties/PublishProfiles/发布到文件夹-调试版.pubxml b/LaunchUrlStudy.SubSite6/Properties/PublishProfiles/发布到文件夹-调试版.pubxml new file mode 100644 index 0000000..874ec1d --- /dev/null +++ b/LaunchUrlStudy.SubSite6/Properties/PublishProfiles/发布到文件夹-调试版.pubxml @@ -0,0 +1,21 @@ + + + + + true + false + true + Debug + Any CPU + FileSystem + ..\Publish\SubSite6-Debug + FileSystem + <_TargetId>Folder + + net8.0 + 32372FF9-05B0-492C-861F-ED056C93E37E + false + + \ No newline at end of file diff --git a/LaunchUrlStudy.SubSite6/Properties/PublishProfiles/发布到文件夹.pubxml b/LaunchUrlStudy.SubSite6/Properties/PublishProfiles/发布到文件夹.pubxml new file mode 100644 index 0000000..4808382 --- /dev/null +++ b/LaunchUrlStudy.SubSite6/Properties/PublishProfiles/发布到文件夹.pubxml @@ -0,0 +1,21 @@ + + + + + true + false + true + Release + Any CPU + FileSystem + ..\Publish\SubSite6 + FileSystem + <_TargetId>Folder + + net8.0 + 32372FF9-05B0-492C-861F-ED056C93E37E + false + + \ No newline at end of file diff --git a/LaunchUrlStudy.SubSite7/Properties/PublishProfiles/发布到文件夹-调试版.pubxml b/LaunchUrlStudy.SubSite7/Properties/PublishProfiles/发布到文件夹-调试版.pubxml new file mode 100644 index 0000000..a0c9261 --- /dev/null +++ b/LaunchUrlStudy.SubSite7/Properties/PublishProfiles/发布到文件夹-调试版.pubxml @@ -0,0 +1,21 @@ + + + + + true + false + true + Debug + Any CPU + FileSystem + ..\Publish\SubSite7-Debug + FileSystem + <_TargetId>Folder + + net8.0 + 7243F3D4-F287-4F55-9FCB-52AE184F4218 + false + + \ No newline at end of file diff --git a/LaunchUrlStudy.SubSite7/Properties/PublishProfiles/发布到文件夹.pubxml b/LaunchUrlStudy.SubSite7/Properties/PublishProfiles/发布到文件夹.pubxml new file mode 100644 index 0000000..7a15a5c --- /dev/null +++ b/LaunchUrlStudy.SubSite7/Properties/PublishProfiles/发布到文件夹.pubxml @@ -0,0 +1,21 @@ + + + + + true + false + true + Release + Any CPU + FileSystem + ..\Publish\SubSite7 + FileSystem + <_TargetId>Folder + + net8.0 + 7243F3D4-F287-4F55-9FCB-52AE184F4218 + false + + \ No newline at end of file diff --git a/LaunchUrlStudy.SubSite8/Properties/PublishProfiles/发布到文件夹-调试版.pubxml b/LaunchUrlStudy.SubSite8/Properties/PublishProfiles/发布到文件夹-调试版.pubxml new file mode 100644 index 0000000..3b334a9 --- /dev/null +++ b/LaunchUrlStudy.SubSite8/Properties/PublishProfiles/发布到文件夹-调试版.pubxml @@ -0,0 +1,21 @@ + + + + + true + false + true + Debug + Any CPU + FileSystem + ..\Publish\SubSite8-Debug + FileSystem + <_TargetId>Folder + + net8.0 + 96A1801F-5F8C-44C6-B8AF-78FDD01A7A26 + false + + \ No newline at end of file diff --git a/LaunchUrlStudy.SubSite8/Properties/PublishProfiles/发布到文件夹.pubxml b/LaunchUrlStudy.SubSite8/Properties/PublishProfiles/发布到文件夹.pubxml new file mode 100644 index 0000000..aafb28c --- /dev/null +++ b/LaunchUrlStudy.SubSite8/Properties/PublishProfiles/发布到文件夹.pubxml @@ -0,0 +1,21 @@ + + + + + true + false + true + Release + Any CPU + FileSystem + ..\Publish\SubSite8 + FileSystem + <_TargetId>Folder + + net8.0 + 96A1801F-5F8C-44C6-B8AF-78FDD01A7A26 + false + + \ No newline at end of file diff --git a/LaunchUrlStudy.sln b/LaunchUrlStudy.sln index 37fe257..987dbba 100644 --- a/LaunchUrlStudy.sln +++ b/LaunchUrlStudy.sln @@ -2,6 +2,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.11.34929.205 MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{EE19F6A8-C2E4-4090-BE83-759F7045D88E}" + ProjectSection(SolutionItems) = preProject + Docs\Ŀ˵.md = Docs\Ŀ˵.md + EndProjectSection +EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LaunchUrlStudy.DefaultApi", "LaunchUrlStudy.DefaultApi\LaunchUrlStudy.DefaultApi.csproj", "{97FB68D0-5944-4624-83A8-BAFE628300DA}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LaunchUrlStudy.SubSite1", "LaunchUrlStudy.SubSite1\LaunchUrlStudy.SubSite1.csproj", "{BDE104AC-A2D2-411D-A171-8387CA80E4A8}" @@ -10,11 +15,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LaunchUrlStudy.SubSite2", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LaunchUrlStudy.SubSite3", "LaunchUrlStudy.SubSite3\LaunchUrlStudy.SubSite3.csproj", "{7BDFEC9E-2818-4BF0-BEDD-120BF6965D00}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{EE19F6A8-C2E4-4090-BE83-759F7045D88E}" - ProjectSection(SolutionItems) = preProject - Docs\Ŀ˵.md = Docs\Ŀ˵.md - EndProjectSection -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaunchUrlStudy.SubSite4", "LaunchUrlStudy.SubSite4\LaunchUrlStudy.SubSite4.csproj", "{21B0DDA7-982D-417D-8D99-22D799DAF067}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LaunchUrlStudy.SubSite5", "LaunchUrlStudy.SubSite5\LaunchUrlStudy.SubSite5.csproj", "{A37F6030-D2FB-4FCC-B796-83F66BACF991}"