--- tags: Q&A, 問題 --- # 程式相關問題集中串  [TOC] ## 撰寫流程 1. 何處遭遇問題 (前端?後端?) 1. 描述遭遇問題狀況 1. 是否已經解決問題? 1. 撰寫解決流程 ## 前端 --- ### 【React】import componets時應在商業邏輯之前 #### 問題描述: 出現以下錯誤 `Error: Import in body of module; reorder to top import/first` #### 遭遇問題及原因: components的載入位置錯誤 需要在其他商業邏輯函式imort之前 #### 解決方式: ```javascript= import <components> from '<componetsPath>' ``` 上面這行需放置在程式尚未執行商業邏輯的地方 --- ### 【React】傳遞components到另一個components #### 問題描述: 將一個完整的components傳給另一個componets #### 遭遇問題及原因: 無法成功傳遞,原因為傳遞方式有錯 #### 解決方式: 原先錯誤的傳遞方式 ```javascript= <A src={B} /> ``` 正確應該為 ```javascript= <A> <B/> </A> ``` 接資料時則使用 `this.props.children` --- ## IDE環境 --- ### 【Visual Studio】存檔後檔案編碼統一成UTF-8 #### 問題描述: 專案底下檔案在Visual Studio預設下儲存後編碼是Big5 在部屬後的檔案或Git上會導致功能不正確 #### 解決方式:  在Visual Studio內的 .editorconfig 內 新增以下內容 ```CS [*] charset = utf-8 ``` 之後儲存的檔案就會預設以UTF-8來進行儲存了 --- ## API端 --- ## 後端 ### 【架站】IIS 錯誤碼 0x8007000d 發生狀況時 #### 問題描述: IIS架設時遇到0x800700d問題 #### 解決方式: 安裝 [Windows Hosting Bundle Installer](https://dotnet.microsoft.com/download/dotnet-core/thank-you/runtime-aspnetcore-3.1.9-windows-hosting-bundle-installer) --- ### 【SQL Server】如何讓使用者只看得到特定資料庫 #### 問題描述: 先前設定權限時雖然A人員只擁有單一資料庫 但在SSMS上能夠看到所有當下其他的資料庫 因此在這邊想避免這樣的事情發生 #### 解決方式: 首先由資料庫伺服器管理者登入最高權限進行申請人帳號設置 勾選申請人員對應資料庫的身分權限後建立帳號 並且在master的查詢畫面中輸入 ```SQL= USE master GO DENY VIEW ANY DATABASE TO <'這裡填寫申請人帳號'> GO ``` 接著登入該帳號便可確認是否完成 --- ### 【SQL Server】刪除使用者帳號出現<無法卸除已登入使用者帳號> #### 問題描述: 在刪除資料庫使用者帳號時 出現了【無法卸除已登入使用者帳號】 ### 原因 當前背景程序有與該帳號相關的作業正在進行 因此需要確認目前服務皆不需要才能進行刪除 #### 解決方式: 【確認】不再需要該使用者帳號後 先進行查詢該使用者執行程序的`SPID` 確認完後透過`kill + <SID>`的指令來強制停止程序 ```SQL= USE master GO # 找出所有該使用者的執行程序並且強制停止 declare @spidTempTable table(spid int) insert into @spidTempTable(spid) select SPID as spid from master.dbo.sysprocesses where loginame = <'請輸入使用者帳號'> while((select count(*) from @spidTempTable) > 0) begin declare @spid smallint declare @sql nvarchar(100) -- 找出程序 select @spid = spid from @spidTempTable -- 撰寫指令格式 set @sql = 'kill ' + RTRIM(@spid) -- 執行指令 exec(@sql) delete @spidTempTable where spid = @spid end -- 刪除使用者 DROP LOGIN '請輸入使用者帳號' ``` 接著登入該帳號便可確認是否完成 --- ## GIT ### 【GIT】 當遇到加入.gitignore失效時 #### 問題描述: 檔案已經存放在git倉庫內 因此後來才加入.gitignore會無效 #### 解決方式: 先清除git Cache內的紀錄 再重新上傳便可以 指令: ```bash= git rm -r --cached . ``` 或是 ```bash= git rm --cached `git ls-files -i --exclude-from=.gitignore` ``` --- ## 資料庫弱點掃描 [教學部分參考]() ### 【中風險】VA1219 Transparent data encryption should be enabled #### 問題描述: 原文: Transparent data encryption (TDE) helps protect against the threat of malicious activity by performing real-time encryption and decryption of the database, associated backups, and transaction log files 'at rest', without requiring changes to the application. This rule checks that TDE is enabled on the database. 翻譯: TDE會將資料庫本身進行加密 在還原資料庫的時候如果沒有憑證或金鑰則不允許存取內部資料 #### 解決方法: 以下說明為如何進行資料庫加密 以及匯入資料庫時所需的行為 1. 進行加密前請先進行備份 2. 建立主要金鑰 3. 建立或取得受到主要金鑰保護的憑證 4. 建立資料庫加密金鑰,並使用憑證保護 5. 設定資料庫使用加密 以下為加密時執行範例 ```mssql= use master go -- 執行前應先確認有沒有前人已建立的master key select * from sys.symmetric_keys Where name='##MS_DatabaseMasterKey##' go -- 若有應選擇沿用 否則會造成錯誤 create master key ENCRYPTION by password = '<在此使用強密碼>' go create CERTIFICATE 憑證名稱 with SUBJECT = '<在此為憑證命名>' go -- 在master DB備份SQL Server憑證及私鑰 backup CERTIFICATE 憑證名稱 TO FILE = '<憑證名稱>.cert' -- 給一個檔名 with private key ( file = '<私鑰檔名>.pk', ENCRYPTION by password = '<私鑰密碼>' -- 這密碼在移轉資料庫時會用到必須牢記 ) go use <要加密的資料庫名稱> go create database ENCRYPTION key with ALGORITHM = AES_256 ENCRYPTION by server CERTIFICATE 憑證名稱 go alter database <要加密的資料庫名稱> set ENCRYPTION on ``` 此時若單純只匯入mdf或ldf檔會報錯 因此得先匯入相關憑證及金鑰 ```mssql= -- Step 1 use master; go -- 先確認沒有才需要創建 select * from sys.symmetric_keys where name='##MS_DatabaseMasterKey##' go -- 創建 create MASTER KEY ENCRYPTION by password = '<這台資料庫的master key>'; Go -- Step 2 USE master; GO -- 以下是重點! -- 利用之前備份的SQL Server憑證和私錀再次建立SQL Server certificate create CERTIFICATE <這台SQL Server的憑證命名> from file = '先前備份的憑證位置/<憑證名稱>.cert' with private key ( file = '先前備份的私鑰位置/<私鑰名稱>.pk', DECRYPTION by password = '<私鑰密碼>' --密碼必須和備份時指定的密碼一樣 ); GO ``` 接著便能附加資料庫進機器了 而關閉TDE的方式如下: ```sql= --關閉TDE加密 use <加密的資料庫> Go --把資料庫加密功能關閉 alter DATABASE <加密的資料庫> set ENCRYPTION off --移除資料庫的ENCRYPTION KEY DROP DATABASE ENCRYPTION KEY Use master Go --查詢哪些資料庫使用SQL Server加密憑證 SELECT db_name(database_id), encryption_state, percent_complete, key_algorithm, key_length FROM sys.dm_database_encryption_keys WHERE db_name(database_id) not in('tempdb') --移除憑證 DROP CERTIFICATE MySQLServerCert --移除Master Key DROP MASTER KEY ``` --- # 架設站台不同憑證 網站繫結需要伺服器名稱指示一定要打勾,否則所有站台會吃到沒有勾取的站台憑證  參考來源:https://blog.pumo.com.tw/archives/815 ## .NetCore ### 【.NetCore】專案發佈時特定檔案也需要發佈到發佈位置時 #### 問題描述: ``` 先前在使用學長API時,發佈的時候SQL資料夾沒有跟著發佈過去而導致執行錯誤 透過底下提及的解決方式,可以將特定的檔案也發佈過去 ``` #### 以下為解決程式碼 ```xml= <ItemGroup> <_CustomFiles Include="SQL/**/*" /> <DotNetPublishFiles Include="@(_CustomFiles)"> <DestinationRelativePath>SQL/%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath> </DotNetPublishFiles> </ItemGroup> ``` #### 程式碼解釋 ```xml= <_CustomFiles Include=[...]/> <!--這段為宣告變數並且內容存專案路徑下的檔案位置--> <DotNetPublishFiles Include="@(_CustomFiles)"> <!--此段則是告訴DotNet在發佈時必須包含該路徑的檔案--> <DestinationRelativePath>I3SQLSettingData/SQL/%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath> <!--此段則是告訴DotNet在發佈時將檔案發佈至何處--> ``` #### 詳細資訊可參考 [官方文件Include檔案說明的部分](https://docs.microsoft.com/zh-tw/aspnet/core/host-and-deploy/visual-studio-publish-profiles?view=aspnetcore-5.0#include-files)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up