OnLoginNeeded in Blazor

Using 10.0.0.1613 according to Delphi.

I have trouble with the OnLoginNeeded in my Blazor app.

Session could not be found is triggered but should not be happening in LoginNeeded

I am a Delphi programmer making his first Blazor app.
So maybe I am doing this completely wrong. In that case, maybe a Blazor programmer can give me some hints.
After a week of testing a trying multiple things I am not going to solve this on my own.
Blazor works with DI and a async event-driven model so I might just no work in such a scenario.

These are my Debug lines, so you can see what I mean:

This line “load De server meldt: Session {3EB6E318-D1B2-4894-B780-97BA8D779625} could not be found” should not be happening.

await StamClient.LoadAsync(EnumStamtabellen.st_Kostendragers)
:counterclockwise_arrows_button: OnLoginNeeded triggered
// Create new session
load De server meldt: Session {3EB6E318-D1B2-4894-B780-97BA8D779625} could not be found
:white_check_mark: LoginRetry

  private async Task Ophalen()
    {
        try
        {
            Console.WriteLine("await StamClient.LoadAsync(EnumStamtabellen.st_Kostendragers) ");
            var raw = await StamClient.LoadAsync(EnumStamtabellen.st_Kostendragers);

            Console.WriteLine("After await StamClient.LoadAsync(EnumStamtabellen.st_Kostendragers) ");
        }
        catch (Exception ex)
        {
            Console.WriteLine("load " + ex.Message);
        }
    }
namespace MyBlazorInteractiveServerApp.Services.RemObjects
{
    public class RemObjectsConnection
    {
        public WinInetHttpClientChannel Channel { get; }

        public readonly BinMessage Message;
        private readonly AppState _appState;


        public RemObjectsConnection(string baseUrl, AppState appState)
        {
            Message = new BinMessage();
            Message.ServerExceptionPrefix = "De server meldt: ";

            _appState = appState;

            Channel = new WinInetHttpClientChannel { TargetUrl = baseUrl };

            Channel.OnLoginNeeded += async (sender, args) =>
            {
                Console.WriteLine("🔄 OnLoginNeeded triggered");

                var username = _appState.Username;
                var password = _appState.Password;

                if (!string.IsNullOrEmpty(username))
                {
                    try
                    {
                        var proxy = new AlgemeenService_AsyncProxy(Message, Channel);

                        Console.WriteLine("// Create new session");
                        await proxy.SetSysInlognaamAsync(username);

                        args.Retry = true;
                        args.LoginSuccessful = true;
                        Console.WriteLine("✅ LoginRetry");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"❌ LoginRetry failed: {ex.Message}");
                        args.Retry = false;
                    }
                }
                else
                {
                    args.Retry = false;
                }
            };
        }
    }
}

Hi,

OnLoginNeeded event is raised when session isn’t found on server-side.

You can avoid this event if you do login manually before calling your method.
it can be something like

  • await proxy.SetSysInlognaamAsync(username);
  • var raw = await StamClient.LoadAsync(EnumStamtabellen.st_Kostendragers);

in this case, OnLoginNeeded event won’t be called because session on server side should be created.

Hi,

I made a different work around, I keep the session alive with a Timer that pings the webservice every 10 minutes.

Hi,

Note: You also can increase session duration on server-side.

check SessionManager.SessionDuration