Open suehshtri opened 1 year ago
Hello, First I want to thank @amaitland for this library. This is very useful.
Well I think is not about the compatible session example, but the session is always null, because OnStarting in SessionMiddleware never triggered. the OnStarting is responsible for sending session to cookie.
My Startup.cs ---ConfigureServices -- > services.AddDistributedMemoryCache(); services.AddSession(opt => { opt.Cookie.HttpOnly = true; opt.Cookie.IsEssential = true; opt.IdleTimeout = TimeSpan.FromHours(1); });
---Configure -- > app.UseSession();
HttpContext.Session.SetString("hi", "Hello world"); --> doesn't work , because "Session" never sent to cookie by SessionMiddleware.
So I find out. SessionMiddleware uses OnStarting to write session cookies, but it's never triggered by the owin server I made a simple test middleware using OnStarting and the result OnStarting never triggered ,
I think All middleware that implements OnStarting/OnComplete is never triggered by owin server. (my oppinion about the flow, OnStarting/OnComplete Triggerd by StartAsync, StartAsync Triggered by RequestDelegate, since it use Owin, StartAsync must be called manually on the server, if I'am not wrong).
so I checked implementation of IHttpResponseFeature, I found the IHttpResponseFeature.OnStarting is empty, it should be implemented. I made small change in OwinFeatureImpl.cs and OwinServer.cs.
and now my session are working, tested with chromly and webview2 sample
I hope this help if someone have the same issue with "onstarting middleware" especialy SessionMiddleware(UseSession).
Thanks.
@marman-hp Thanks for posting your findings 👍
Can you please submit your changes as a PR
so they can be included in the library itself. Thanks.
Consider adding an example that is compatible with server code that uses a session and session cookie.