# OnLoginNeeded in Blazor

**URL:** https://talk.remobjects.com/t/onloginneeded-in-blazor/32218
**Category:** Remoting SDK
**Created:** [September 22, 2025, 8:37am UTC](https://talk.remobjects.com/t/onloginneeded-in-blazor/32218 "2025-09-22T08:37:12Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![allinco1](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/a/b782af/32.png) [@allinco1](https://talk.remobjects.com/u/allinco1)
#### Post date: [September 22, 2025, 8:37am UTC](https://talk.remobjects.com/t/onloginneeded-in-blazor/32218/1 "2025-09-22T08:37:12Z")

</div>

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)  
🔄 OnLoginNeeded triggered  
// Create new session  
load De server meldt: Session {3EB6E318-D1B2-4894-B780-97BA8D779625} could not be found  
✅ LoginRetry

```auto
  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);
        }
    }

```

```auto
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;
                }
            };
        }
    }
}

```

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [September 29, 2025, 7:22am UTC](https://talk.remobjects.com/t/onloginneeded-in-blazor/32218/2 "2025-09-29T07:22:20Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![allinco1](https://talk.remobjects.com/letter_avatar_proxy/v4/letter/a/b782af/32.png) [@allinco1](https://talk.remobjects.com/u/allinco1)
#### Post date: [September 30, 2025, 6:30am UTC](https://talk.remobjects.com/t/onloginneeded-in-blazor/32218/3 "2025-09-30T06:30:58Z")

</div>

Hi,

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

---

<div class="post-metadata">

### Author: ![EvgenyK](https://talk.remobjects.com/user_avatar/talk.remobjects.com/evgenyk/32/16_2.png) [@EvgenyK](https://talk.remobjects.com/u/EvgenyK)
#### Post date: [September 30, 2025, 9:56am UTC](https://talk.remobjects.com/t/onloginneeded-in-blazor/32218/4 "2025-09-30T09:56:37Z")

</div>

Hi,

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

check [SessionManager.SessionDuration](https://docs.remotingsdk.com/API/Delphi/Classes/TROCustomSessionManager/#SessionDuration)
