Web 應用無法直接存取硬體,解決方案:建立 WinForm 控件專案 (ReadCardControl),封裝 P/Invoke 呼叫閱讀機 DLL (Sdtapi.dll),再於 ASPX 頁面引用該控件。
[DllImport("Sdtapi.dll")] private static extern int InitComm(int iPort);
[DllImport("Sdtapi.dll")] private static extern int Authenticate();
[DllImport("Sdtapi.dll")] private static extern int ReadBaseInfos(StringBuilder Name, StringBuilder Gender, ...);
[DllImport("Sdtapi.dll")] private static extern int CloseComm();
InitComm(1001)Authenticate()ReadBaseInfos(...) 填充姓名、性別、民族、生日、身分證號、地址、發證機關、效期起迄photo.bmpCloseComm()資料存入陣列 arrys 供上層呼叫,並以 Beep 提示讀卡成功。