發表文章

解決 ASP.NET Core The Development environment shouldn't be enabled for deployed applications 問題

圖片
 今天發布專案後瀏覽網頁,出現了錯誤訊息 Error. An error occurred while processing your request. Request ID:   00-0db8ab846988d425dedca4ad62815575-d671b532783951b3-00 Development Mode Swapping to  Development  environment will display more detailed information about the error that occurred. The Development environment shouldn't be enabled for deployed applications.  It can result in displaying sensitive information from exceptions to end users. For local debugging, enable the  Development  environment by setting the  ASPNETCORE_ENVIRONMENT  environment variable to  Development  and restarting the app. 如果想看到詳細的錯誤訊息,要網址資料夾下,打開 web.config 原始的內容長這樣 在 aspNetCore 標籤中加入 <environmentVariables>          <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />         </environmentVariables>     如下圖所示 儲存後重新整理網頁,就可以看到詳細的錯誤訊息囉! {"errdesc":"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The s

解決 Visual Studio 2022 找不到 ASP.NET Web 應用程式 (.NET Framework) 專案問題

圖片
   今天打開 Visual Studio 2022   發現找不到使用 .NET Framework 的 ASP.NET 的 Web 專案 查了一下原因,原來是當初安裝時沒有設定好, 請關閉 Visual Studio, 開啟 Visual Studio Installer,按 修改 按紐 之前安裝時已勾選 ASP.NET 與網頁程式開發 , 在右邊的安裝詳細資料中, 要將 ASP.NET 與網頁程式開發 的選項展開, 在 選擇性 選項中,勾選 .NET Framework 專案與項目範本 等待安裝完畢後,重啟  Visual Studio 2022 即可

使用 IG API 撈取 IG 貼文的留言

圖片
  登入 https://developers.facebook.com/ 商業帳號的下拉式選單若沒有資料可以選,要記得先去 meta 後台 https://business.facebook.com/ 設定管理權限 回到開發後台 測試 API https://developers.facebook.com/docs/instagram-api/getting-started https://developers.facebook.com/docs/instagram-api/reference/ig-media https://developers.facebook.com/docs/instagram-api/reference/ig-media/comments 也可以使用 fields 撈取想要的欄位 欄位名稱可參考此網頁的下方 https://developers.facebook.com/docs/instagram-api/reference/ig-comment

add-migration 遇到 The foreign key property 'Article.ArticleTypeId1' was created in shadow state 問題

圖片
環境: asp.net core MVC 搭配 sql server 2014 使用 entity framework core code first 下  add-migration 指令時,發現奇怪的訊息       The foreign key property 'Article.ArticleTypeId1' was created in shadow state because a conflicting property with the simple name 'ArticleTypeId' exists in the entity type, but is either not mapped, is already used for another relationship, or is incompatible with the associated primary key type. See https://aka.ms/efcore-relationships for information on mapping relationships in EF Core.  先來看模型,有兩個 Article.cs 與 ArticleType.cs 文章是 Article.cs  Article.cs 裡面有一個 ArticleTypeId 欄位用來記錄文章的分類 另外也宣告一個 ArticleType 的導覽屬性 文章分類是 ArticleType.cs  產生的 Migration 內容 ArticleType 在 Article.cs 裡面是導覽屬性,加了就會跑出  ArticleTypeId1 覺得超級奇怪 若沒宣告 ArticleType  屬性是不會出錯的 看了很久才發現... ArticleType.cs 的 Id 屬性的型別打錯了 應該要打 int 我打成 string  XDDDDD 浪費了一個下午