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

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

Closed
DecGio opened this issue Jun 4, 2024 · 5 comments · Fixed by #565
Closed

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

DecGio opened this issue Jun 4, 2024 · 5 comments · Fixed by #565
Labels
In-PR Issues that have a PR open for them. Needs: Triage 🔍 Label added to new issues which need Triage

Comments

@DecGio
Copy link

DecGio commented Jun 4, 2024

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?

@dotnet-policy-service dotnet-policy-service bot added the Needs: Triage 🔍 Label added to new issues which need Triage label Jun 4, 2024
@tsi-kyle
Copy link

tsi-kyle commented Jun 4, 2024

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

@DecGio
Copy link
Author

DecGio commented Jun 5, 2024

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

Screenshot 2024-06-05 alle 10 03 37

@Mciver91
Copy link

Mciver91 commented Jul 4, 2024

I can confirm this is also an issue for me.

@erpardeepkaushik
Copy link

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.

@dotnet-policy-service dotnet-policy-service bot added the In-PR Issues that have a PR open for them. label Dec 11, 2024
@twsouthwick
Copy link
Member

Pushing a change so that the last one wins

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

Successfully merging a pull request may close this issue.

5 participants