Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PRevenitng a session from being created in OnBeforeDIspatch
#1
Next dumb question:

In IWXI, I could set handled to true in the OnBeforeDispatch (after sending a bit of html to the response) and it would end the session there and then.

When I'm trying to do the same in IW XV, it *does* run the code, but seems to run the OnBeforeDispatch multiple times for a single connection, before either erroring or just rendering the front page of my app - there is no Handled property for me to tell it to stop.

What should I be using instead? I want to generate different html based on which subdomain was used to connect, and not have to redirect the URL

(IW XI code:

Responded := false;
    Response.StatusCode := 200;

    DirList := TStringList.Create;


  GetSubDirectories(IncludeTrailingPathDelimiter(ExtractFileDir(ParamStr(0)))
        + 'wwwroot\googlebot', DirList);

    if DirList.count > 0 then
      for x := 0 to DirList.count - 1 do
      begin
        if pos(UpperCase(ExtractFileName(ExcludeTrailingPathDelimiter
                (DirList[x]))), UpperCase(Request.Host)) > 0 then
        begin
          mystrings := TStringList.Create;
          mystrings.LoadFromFile(DirList[x] + '\index.html');
          Response.ContentType := 'text/html';
          Response.content := '';
          for y := 0 to mystrings.count - 1 do
          begin
            Response.content := Response.content + mystrings[y] + #10#13;
          end;
          Response.SendResponse;
          Responded := true;
          break;
        end
      end;

    if not Responded then
    begin

      Response.ContentType := 'text/html';
      Response.content := html;
      Response.SendResponse;

    end;


)
Reply
#2
Thanks for everyone's help on this via Telegram - we've been trying to get the googlebot response page to show the same URL as the main page, but having tested using the redirected URLs google is still showing the correct URL, so it's not as needed as we feared.
Reply
#3
Hi Sam,

For others in the future, I'm going to repost some of those responses.  Telegram doesn't "thread" by subject, and search isn't as useful so things like this are much more helpful to note here in the forum.  If I missed part of the conversation, or quoted it incorrectly, please post a response.
Thanks,
Dan

Chad:
Depending on your context, ContentHandlers may be what you are looking for. There are examples in our demos and they are documented on our site.
https://doc.atozed.com/en/iw15/develop/c...-handlers/
17 hooks onto 15 using ContentHandlers

Sam
I'm trying to avoid doing it with redirecting though - I want the URL to be the same as default, with a different html response.
This is the funcitonality that we had with XI, that I'm trying to recreate

Chad
If its on the first page, look at the onnewsession event in SC, it allows you to choose which page is returned for main

Alex:
OnBeforeDispatch does happen multiple times. Each request/response goes through OnBeforeDispatch. During application start up multiple requests are sent to the server. There is nothing wrong there
If you want to block a request before it creates a new session IW 15 gives you the OnBeforeNewSession event
TOnBeforeNewSessionEvent = procedure(const aUrlPath: string; aRequest: THttpRequest; out vCanCreate: Boolean) of object;
Just set vCanCreate to false and the user will get a 404 and no session will be created
Reply
#4
For future reference, this was the response on the Telegram channel:

OnBeforeDispatch does happen multiple times. Each request/response goes through OnBeforeDispatch. During application start up multiple requests are sent to the server. There is nothing wrong there

If you want to block a request before it creates a new session IW 15 gives you the OnBeforeNewSession event


TOnBeforeNewSessionEvent = procedure(const aUrlPath: string; aRequest: THttpRequest; out vCanCreate: Boolean) of object;


Just set vCanCreate to false and the user will get a 404, and no session will be created
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)