#1 2025-04-02 10:44:04

testgary
Member
Registered: 2025-02-06
Posts: 3

Interaction with TMVCApplication based on methods.

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

#2 2025-04-02 14:41:43

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,952
Website

Re: Interaction with TMVCApplication based on methods.

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

#3 2025-04-03 03:53:29

Chaa
Member
Registered: 2011-03-26
Posts: 253

Re: Interaction with TMVCApplication based on methods.

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

#4 2025-04-03 08:02:06

testgary
Member
Registered: 2025-02-06
Posts: 3

Re: Interaction with TMVCApplication based on methods.

Thank you very much for “AB”'s response, and the test was successful. I appreciate your sharing and dedication.

Offline

#5 2025-04-03 08:07:27

testgary
Member
Registered: 2025-02-06
Posts: 3

Re: Interaction with TMVCApplication based on methods.

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

Board footer

Powered by FluxBB