Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TIWServerController: OnBeforeNewSession/OnNewSession
#1
Hi,

I have found that a new session is always created with an HTTP request
and the OnNewSession event is triggered, whether in the OnBeforeNewSession event
the parameter vCanCreate is set to true or false.

Should a new session not only be created with vCanCreate = true


C++Builder 10.3.3

IntraWeb 15.1.22

Regards
Juergen
Reply
#2
Hi,

I found the following thread that confirms this.

I wonder how the value of vCanCreate can be returned if it is not a reference.

void __fastcall TIWServerController::OnBeforeNewSession(const UnicodeString aUrlPath,THttpRequest *aRequest, bool vCanCreate)

Could someone from ATOZED answer please?

Regards
JuergenS

(06-10-2020, 05:35 PM)JuergenS Wrote: Hi,

I found the following thread that confirms this.

I wonder how the value of vCanCreate can be returned if it is not a reference.

void __fastcall TIWServerController::OnBeforeNewSession(const UnicodeString aUrlPath,THttpRequest *aRequest, bool vCanCreate)

Could someone from ATOZED answer please?

Regards
JuergenS
The thread: PRevenitng a session from being created in OnBeforeDIspatch
Reply
#3
This is the method signature, in Delphi, of course. As you can see, it is an "out" parameter, thus it is passed by reference.

Code:
procedure TIWServerController.IWServerControllerBaseBeforeNewSession(const aUrlPath: string; aRequest: THttpRequest; out vCanCreate: Boolean);

If the compiler doesn't generate the appropriate code, that's something new - and unexpected - to me. Till this date, other than a minor glitches regarding C++ which required manual intervention, pretty much everything behaves exactly the same.
I didn't even look at the C++ code generated in this case, so I'm not saying that this is the case or not.... but to me it is kind of unbelievable that this kind of issue would stay unnoticed for so long....

Anyway, I'll have a look and get back to you on this
Reply
#4
Please open your IWServerControllerBase.hpp file. In there you will find the definition of the method type:

Code:
typedef void __fastcall (__closure *TOnBeforeNewSessionEvent)(const System::UnicodeString aUrlPath, Iw::Http::Request::THttpRequest* aRequest, /* out */ bool &vCanCreate);

As you can see the definition is correct. The event signature though is wrong once created in RAD Studio 10.2.3 (at least) and I think this is a bug in RAD Studio but I couldn't find any reference to it.

There is an easy fix though. Just manually edit the parameter to match the original method signature, in both your ServerController.cpp and ServerController.h files as:

In ServerController.cpp file:

Code:
#pragma startup setServerController
void __fastcall TIWServerController::IWServerControllerBaseBeforeNewSession(const UnicodeString aUrlPath,
  THttpRequest *aRequest, bool &vCanCreate)
{
  vCanCreate = false;
}

In ServerController.h file:

Code:
void __fastcall IWServerControllerBaseBeforeNewSession(const UnicodeString aUrlPath,

          THttpRequest *aRequest, bool &vCanCreate);

Please notice that I just added an ampersand (&) in front of vCanCreate parameter, so it is passed as reference. 

I tested it in a C++ project and it works correctly (try setting vCanCreate = false as I did above and you will receive a 404 error every time you try to create a new session). 

I'll test it in latest RAD Studio 10.4 and see if it behaves the same. Other than that, I think the only other thing I can do is report it to Embarcadero so they can fix it.

Cheers
Reply
#5
Yes, I had seen the definition for TOnBeforeNewSessionEvent in IWServerControllerBase.hpp.

But if i create the event handler for TOnBeforeNewSessionEvent in the Object Inspector, the wrong code will definitely be generated!

Correct event functions are generated for all other events with boolean return values, which do not have the C comment "/ * out * /" in their definition.
TOnExceptionEvent
TOnParseParameterEvent
TOnWindowIdChangedEvent


I have now used the recommended workaround.

Regards
Juergen
Reply
#6
> But if i create the event handler for TOnBeforeNewSessionEvent in the Object Inspector, the wrong code will definitely be generated!

I guess we can agree that this is a bug in RAD Studio, not IW, right? The code is generated by RAD Studio IDE from the method definition in the installed package. The code in package is correct as you can see. There is nothing we can do about it other than notify Embarcadero
Reply
#7
Yes, I also think that should be reported to Embarcadero.

I am now using C ++ Builder 10.4 (Sydney).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)