Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sharing Session between .NET Framework application and .Net7 application is not working #453

Open
meghanavedpathak opened this issue Dec 1, 2023 · 13 comments
Labels
Needs: Triage 🔍 Label added to new issues which need Triage

Comments

@meghanavedpathak
Copy link

meghanavedpathak commented Dec 1, 2023

I am trying to Set Session variable in .NET framework application and access it in .NET 7 application using link https://learn.microsoft.com/en-us/aspnet/core/migration/inc/remote-session?view=aspnetcore-7.0 however I am unable to get value of session variable in .NET Core.

I did following changes

.NET Framework -
Added Nuget package Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices

Added below code in global.asax.cs -Application_Start function

SystemWebAdapterConfiguration.AddSystemWebAdapters(this)
.AddJsonSessionSerializer(options =>
{
// Serialization/deserialization requires each session key to be registered to a type
options.RegisterKey("test");
})
// Provide a strong API key that will be used to authenticate the request on the remote app for querying the session
// ApiKey is a string representing a GUID
.AddRemoteAppServer(options => options.ApiKey = "03f74e3e-d690-4806-b0a7-e66f89215bb3")
.AddSessionServer();

.NET 7 Changes

builder.Services.AddSystemWebAdapters()
.AddJsonSessionSerializer(options =>
{
// Serialization/deserialization requires each session key to be registered to a type
options.RegisterKey("test");
}) .AddRemoteAppClient(options =>
{
// Provide the URL for the remote app that has enabled session querying
options.RemoteAppUrl = new(builder.Configuration["ReverseProxy:Clusters:fallbackCluster:Destinations:fallbackApp:Address"]);
// Provide a strong API key that will be used to authenticate the request on the remote app for querying the session
options.ApiKey = "03f74e3e-d690-4806-b0a7-e66f89215bb3";
})
.AddSessionClient();

Added app.MapDefaultControllerRoute().RequireSystemWebAdapterSession(); ;

@dotnet-policy-service dotnet-policy-service bot added the Needs: Triage 🔍 Label added to new issues which need Triage label Dec 1, 2023
@sgarnovsky
Copy link

sgarnovsky commented Dec 5, 2023

I have got something the same but under .Net 8.
Originally I'd already created a project using .Net 6 and SystemWebAdapters using version 1.2.0 and it worked fine.
After migrating to the .Net 8 and SystemWebAdapters 1.3.0 (nuget package) Session from the System.Web.HttpContext is returned as a null reference.

One thing I see this github project refers 1.2.0 version. It is possible the 1.3.0 has changed initialization steps or just moved to other place.

So for now, I just downgraded the SystemWebAdapters packages back to 1.2.0 version. Confirmed the Session sharing works fine under .Net 8 in this case.

@lalitkhanna
Copy link

@sgarnovsky I've tried with all versions .Net6,7,8. Its not at all working, Can you pls share your code ?

@sgarnovsky
Copy link

My code is here. It's mostly the same as yours above. I only use a custom session serializer.
Followed instructions from this video to make it working.
https://www.youtube.com/watch?v=zXoGXbB3JDI

services.AddSystemWebAdapters()
.AddSessionSerializer()
.AddMssAdminSessionSerializer()
.AddRemoteAppClient(options =>
{
options.RemoteAppUrl = new(Configuration.GetMigrationLegacyAppAddress());
options.ApiKey = Configuration.GetMigrationRemoteAPIKey();
})
.AddSessionClient();

app.MapRazorPages()
.RequireSystemWebAdapterSession();

@lalitkhanna
Copy link

@sgarnovsky I did same but somehow still System.Web.HttpContext.Current.Session is null. Any Possibilities if you can share your code in Github?
I'm using .Net 8 & SystemWebAdapters ver is 1.3 & also tried 1.2 but nothing happened.

@sgarnovsky
Copy link

sgarnovsky commented Dec 6, 2023

Unfortunately, I can't share my code (it is a big customer project).
I guess, as a session is null even for the 1.2 package version, you may miss to call the RequireSystemWebAdapterSession in a right way...
Please try a [Session] attribute too, as described here:
https://stackoverflow.com/questions/73638526/session-sharing-between-asp-net-webforms-and-asp-net-core

Also, do not forget to apply a middleware initialization call: app.UseSystemWebAdapters();

And of course, check the session instance from the "System.Web.HttpContext":
System.Web.HttpContext.Current?.Session

@lalitkhanna
Copy link

Dear @sgarnovsky

Able to Achieve , now its working. Thankyou so much for your help.

@sgarnovsky
Copy link

@lalitkhanna please post the details you found to fix on your side.
And, of course, let us know what a version of SystemWebAdapters you ended up to use as well as .Net version.

@lalitkhanna
Copy link

@sgarnovsky I found couple of points for my fix.

  1. Add all four .Netget Packages for Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices
  2. Added [Session] attribute in Controller
  3. Microsoft.AspNetCore.SystemWebAdapters.FrameworkServices 1.2 Ver
  4. .Net 8

Rest all points are same which @meghanavedpathak added.

@sgarnovsky
Copy link

@lalitkhanna thank you for details.
Please let us know if you tried the 1.3 version.

@meghanavedpathak
Copy link
Author

I tried by using .Net 6 and SystemWebAdapters using version 1.2.0 but its not working on my side. We do not want application to be on .NET 8 currently. I will check video you provided. Thank you for help.

@Jbarker1
Copy link

Same here, using .net 8 and going back to version 1.2.0 with the rest following the remoteauth identity sample works.

@lalitkhanna
Copy link

Another issue, while trying to access the Asp.net web form pages then getting ERR_HTTP2_PROTOCOL_ERROR .(in console)

Anybody face this issue ?

@joperezr
Copy link
Member

@meghanavedpathak is this issue still relevant?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Triage 🔍 Label added to new issues which need Triage
Projects
None yet
Development

No branches or pull requests

5 participants