1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | procedure TWebModule.DSServerConnect( DSConnectEventObject: TDSConnectEventObject); var _Session: TDSSession; begin try if Assigned(DSConnectEventObject.ChannelInfo) then begin _Session := TDSSessionManager.GetThreadSession; if Assigned(_Session) then begin if _Session.GetData( 'RemoteAddr' ) = '' then _Session.PutData( 'RemoteAddr' , DSConnectEventObject.ChannelInfo.Info); end; end; except end; end; |
今天測試大概是可以解決:
1. Request.RemoteAddr 不定時會存取失敗
2. REST 方法呼叫時,DSConnectEventObject.ChannelInfo 和 TDSSessionManager.GetThreadSession 必會存取失敗的問題
可能有人會問,如果使用 REST 方法時又想記錄 IP 的時候該怎麼處理?
目前原則上就只能避開使用 TDSSessionManage 。
至於什麼時候會修正這個 Bug ?
嗯.
.
.
.
……我想應該是在不久的將來吧!
See also:
- QC#121931 Request.RemoteAddr may causes Access Violation in TDSServer.OnConnect event
(Request not access in DSServer.OnConnect Event) - QC#121930 TDSServer can not get the Client IP via Request.RemoteAddr in its OnConnect event
(DSServer can not get the Client IP) - REST Service 的壓力測試時發生讀不到 RemoteIP 的問題
- Delphi XE5 Rest Datasnap Server. Getting Client IP Address