2023年10月31日 星期二

.Net Core 如何新增Area區域

1.專案右鍵 > 加入 > 新增Scaffold項目
2.MVC區域 > 加入
3.在Program.cs
 app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");
加入
 app.MapControllerRoute(
    name: "MyArea",
    pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");
4.在Controller加入Area tag
參考資料
ASP.NET Core 中的區域

.Net Core 發佈後多了許多語言檔資料夾

.net發佈網站後可能會多了許多沒用的語言檔資料夾
找到專案的.csproj(或右鍵編輯專案檔)
 <PropertyGroup>
   <TargetFramework>net6.0</TargetFramework>
 </PropertyGroup>
修改
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
	<SatelliteResourceLanguages>en-US;zh-TW</SatelliteResourceLanguages>
  </PropertyGroup>
乾淨多了
參考資料
【笨問題】防止 .NET 編譯產生不需要的多語系資源檔
ASP.Net Core exclude published language directories other than english