You are not logged in.
procedure TRestServerDB.GetCaptcha(Ctxt: TRestServerUriContext);
var
Context: TBinaryCookieGenerator;
begin
Context.Init('MyCustomCookieName');
Context.Generate(Cookie, 0, @CookieData, TypeInfo(TCookieData));
end;
The session generated by TBinaryCookieGenerator is different from the session generated by TMVCApplication, which causes the session values in the TBinaryCookieGenerator.Validate method to differ. How can I share their session and cookie? I still haven’t solved this issue today.
Offline
TBinaryCookieGenerator is a .... generator ... so it needs to maintain its own instance during your own server process.
So just use the existing TBinaryCookieGenerator instance of your process class, then use it to generate the cookie from the method, if needed.
Offline
1. Add GetCaptcha to your TMVCApplication descendant (TMyMvcApp).
2. In TMyMvcApp.Start call (RestModel as TRestServer).ServiceMethodRegister('GetCaptcha', GetCaptcha, {aByPassAuthentication}True);
3. Now use CurrentSession:
procedure TMyMvcApp.GetCaptcha(Ctxt: TRestServerUriContext);
begin
CurrentSession.CheckAndRetrieve(...);
end;
Offline
Thank you very much for “AB”'s response, and the test was successful. I appreciate your sharing and dedication.
Offline
Thank you very much for “Chaa”'s response as well. I tested your method, and it works perfectly; it’s even more convenient.
Mormot is a great piece of work, and Pascal shines again!
Offline