Skip to content

Session State is not working or Could not redirect to WebForms page. #382

Open
@AjayKumar22n

Description

@AjayKumar22n

I am trying to migrate few of the pages from webforms application (Session oriented APP) to .Net core Blazor Server app (.Net 7), either I could not get the session object in the .net core or could not redirect to webforms page. Can you please suggest.

if I invoke RequireSystemWebAdapterSession() after MapBlazorHub middleware pipeline like below , I am able to set the session (System.Web.HttpContext.Current.Session!["sessionstring"] = "Temp Session";)

but System could not navigate from blazor to framework app.

### app.MapBlazorHub().RequireSystemWebAdapterSession();
app.MapRazorPages();
app.MapBlazorPages("/_Host");

app.MapReverseProxy();

suppose if I change code like below without RequireSystemWebAdapterSession, Navigation will work from Blazor Server app to framework app. But could not read or set the session in the core app, Current.Session is showing null.

app.MapBlazorHub();
app.MapRazorPages();
app.MapBlazorPages("/_Host");

app.MapReverseProxy();

if I use both then application is having ambiguous matching endpoint - which is not correct.
app.MapBlazorHub();
app.MapBlazorHub().RequireSystemWebAdapterSession();

here is the error from console:
System.Net.Http.HttpRequestException: Response status code does not indicate success: 400 (Bad Request).
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at Microsoft.AspNetCore.SystemWebAdapters.SessionState.RemoteSession.RemoteAppSessionStateManager.SetOrReleaseSessionData(ISessionState state, CancellationToken cancellationToken)
at Microsoft.AspNetCore.SystemWebAdapters.SessionState.RemoteSession.RemoteSessionState.CommitAsync(CancellationToken token)
at Microsoft.AspNetCore.SystemWebAdapters.SessionMiddleware.ManageStateAsync(HttpContext context, SessionAttribute metadata)

I have set up unique apikey in both places, and tried with both latest adapters version 1.2.0 is also, if i use latest having different error.

Please see the complete code in the Program.cs here.

I have set up everything as described in the documentation -
var app = builder.Build();
app.UseStaticFiles();

app.UseForwardedHeaders();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

//app.UsePathBase("/" + pathBase);
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();

app.UseSystemWebAdapters();

//app.UseSession();
//app.UseCors(x => x.AllowAnyOrigin());
//app.UseRequestLocalization();
app.UseAuthorization();

//app.MapBlazorHub().BufferResponseStream().PreBufferRequestStream().RequireSystemWebAdapterSession();

// The following Require System Web Adapter session is required for MapBlazorHub to use the session context object.

app.MapBlazorHub().RequireSystemWebAdapterSession();
app.MapRazorPages();//.RequireSystemWebAdapterSession();
app.MapBlazorPages("/_Host");

app.MapReverseProxy();
app.Run();

please let me know if any additional details are needed.
appsettings.json: (reverse proxy)

"ReverseProxy": {
"Routes": {
"fallbackRoute": {
"ClusterId": "fallbackCluster",
"Order": "1",
"Match": {
"Path": "{**catch-all}"
}
}
},
"Clusters": {
"fallbackCluster": {
"Destinations": {
"fallbackApp": {
//This needs to be changed based on the environment.
"Address": "https://localhost/{aaa}"
}
}
}
}
}

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestneeds author feedbackThe author of this issue needs to respond in order for us to continue investigating this issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions