dotnet / systemweb-adapters

MIT License
337 stars 59 forks source link

error 500 (Internal Server Error) when I try to access the session #504

Open DecGio opened 4 months ago

DecGio commented 4 months ago

I'm using version 1.4 of this libraries. on the global.asax I have this configuration:

SystemWebAdapterConfiguration.AddSystemWebAdapters(this)
    .AddProxySupport(options => options.UseForwardedHeaders = true)

    .AddJsonSessionSerializer(options =>
    {
        // Register session item names/types that will be read or written
        options.RegisterKey<string>("Test-Value");

    })
    .AddRemoteAppServer(options =>
    {
        options.ApiKey = builder.Configuration["RemoteAppApiKey"];
    }).AddSessionServer();

in Programm.cs

builder.Services.AddSystemWebAdapters()
    .AddJsonSessionSerializer(options =>
    {
        // Serialization/deserialization requires each session key to be registered to a type
        options.RegisterKey<string>("Test-Value");
    })
    .AddRemoteAppClient(options =>
    {
        options.RemoteAppUrl = new (builder.Configuration["ProxyTo"]);

        options.ApiKey = builder.Configuration["RemoteAppApiKey"];
    })
    .AddSessionClient(); 

in controller (migrated in .net 8):

namespace testsession.Controllers
{
    [Session]
    public class SessionController : Controller
    {
        // GET: Session
        public ActionResult Index()
        {
            var sess = System.Web.HttpContext.Current?.Session?["Test-Value"];
            return View();
        }
    }
}

when I try to access the page it gives me this error:

HttpRequestException: Response status code does not indicate success: 500 (Internal Server Error).
System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
Microsoft.AspNetCore.SystemWebAdapters.SessionState.RemoteSession.RemoteAppSessionStateManager.GetSessionDataAsync(string sessionId, bool readOnly, HttpContext callingContext, CancellationToken token)
Microsoft.AspNetCore.SystemWebAdapters.SessionState.RemoteSession.RemoteAppSessionStateManager.CreateAsync(HttpContext context, SessionAttribute metadata)
Microsoft.AspNetCore.SystemWebAdapters.SessionMiddleware.ManageStateAsync(HttpContext context, SessionAttribute metadata)
Microsoft.AspNetCore.SystemWebAdapters.PreBufferRequestStreamMiddleware.InvokeAsync(HttpContext context)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

how can I solve it?

tsi-kyle commented 4 months ago

I think in the program.cs you need:
options.RegisterKey<string>("Test-Value"); instead of
options.RegisterKey("Test-Value");

DecGio commented 4 months ago

I replaced it as you told me but nothing. Always the same error :(

Screenshot 2024-06-05 alle 10 03 37
Mciver91 commented 3 months ago

I can confirm this is also an issue for me.

erpardeepkaushik commented 1 month ago

by mistake, i added duplicate entry ( options.RegisterKey("testId");) in program.cs and global.aspx.cs. and encountered the same error. removing the duplicate entry works for me.