-
Notifications
You must be signed in to change notification settings - Fork 62
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
Session State is not working or Could not redirect to WebForms page. #382
Comments
@AjayKumar22n I'm a little confused by your example here. Can you clean it up a little so it's something we can easily reproduce? |
I think you're hitting the issue that is described here: https://learn.microsoft.com/en-us/aspnet/core/migration/inc/blazor?view=aspnetcore-7.0. Take a look and let me know if that solves it |
Yes - then I can check it out directly :) |
Thank You for your valuable time to look into this, Here is the Git Hub path for the sample one. |
I'm not able to build it (can't find Telerik.UI.for.Blazor) - can you make it so it can build on any computer? Taking a look, though, I think this is problem: - app.MapBlazorHub().RequireSystemWebAdapterSession();
+ app.MapBlazorHub();
app.MapRazorPages();//.RequireSystemWebAdapterSession();
- app.MapBlazorPages("/_Host");
+ app.MapBlazorPages("/_Host").RequireSystemWebAdapterSession();
app.MapReverseProxy(); The call to |
I have tried the recommended steps, still the session is not working for the Razor pages. Can you please check out the latest of the master branch - https://github.com/AjayKumar22n/SystemWebAdapterWithSession |
Can you please confirm on the changes that i need to take care, Did I do any mistakes? |
Hey Can you please let us know if we have any workaround for this to handle both Session state and navigation? |
@AjayKumar22n I'm hitting something weird with your solution and it seems to crash VS whenever I try to load it. I'm going to try on a different machine.... |
@twsouthwick, Can you please use the following Repo: https://github.com/AjayKumar22n/MigrationUsingAdapters |
Hi @twsouthwick, It would really help us if you can you provide us any resolution. |
Hey Can you please let us know if we have any workaround for this to handle both Session state and navigation? |
Sorry for a delayed response. I think I understand the issue, and unfortunately, it's probably not an easy fix. In a Blazor server application, the existence of an HttpContext is not guaranteed and shouldn't be relied on (see dotnet/aspnetcore#17585 (comment)). However, some good news: with the updates coming in .NET 8 for true server side rendering of blazor, an HttpContext will be available there to enable this scenario (may need some updates on our side, but we think it will be better). It'll be available in RC2 release thanks to this PR: dotnet/aspnetcore#50253. If you want to try that out (via nightly builds), please let us know if there's anything we need to expose/enable here to integrate with it. |
@AjayKumar22n Were you able to get it working using .NET 8? @twsouthwick I've tried and the session is no longer null, but I keep getting the following errors:
Program.cs:
Global.aspx.cs:
Home.razor:
|
It seems to be working now. I am not sure what I did, but I am not longer getting any error messages. I tried recreating the problem with the above code and it works fine now. |
@pockets3407 this is great to hear! Would you be up for submitting a sample to the repo with this new set up? |
@twsouthwick Sure, I can submit something once .NET 8 has been released |
Great! Our repo is already targeting. Net 8 so no need to wait if you have something. |
@twsouthwick Sorry about the delay. I am in the middle of adding the sample here: https://github.com/pockets3407/systemweb-adapters/tree/blazor-session-sample. I am having issues getting it working.
EDIT: I realized that HttpContext is not intended to work with Server render mode. |
Thanks @pockets3407 - I'll take a look in the morning |
@twsouthwick I was wondering if there was any update on this. I have noticed #453 and #455 have been created and I think these are related. |
Hello, i tried an example but seems .net8 and yarp 1.3 is not working together or there is a bug in VS2022. i always get the session values null in asp.net core app. but downgrading to all packages of system web adaptors to 1.2 works seamlessly. please advise what could be the issue. please find the repos links with ver 1.3 https://github.com/erpardeepkaushik/TestWebCore |
Hello @twsouthwick, @AjayKumar22n @pockets3407 is there any solutions exists for this issue. I tried another example where session sharing is working between ASP.net web form app and Razor Core App. but not working with Blazor App. Also if we enable all below settings then it works with Blazor but with lot of error in yarp(no redirecting properly only one Blzoor app tab work at time.) app.MapBlazorHub().RequireSystemWebAdapterSession(); Could you please advise a solutions. we have an urgent project and we stuck here now. SystemWebAdapter V1.3 is not working at all. we are working with SystemWebAdapter1.2 at the moment with NET 8. |
@twsouthwick I submitted by Pull Request for my sample. The only issue I have found is that I get an exception that breaks navigation. This occurs when I navigate from an InteractveServer page (Counter) to a static page (Home, Weather). |
@pockets3407 @twsouthwick its couple of months now and we are still waiting as we are stuck while upgrading our Webform app to asp.net core. please release the next version asap. |
@erpardeepkaushik With the current workaround that I described in my sample, I did not have any issues using 1.4 SystemWebAdapters to transfer session from WebForms to Blazor.
Besides the workaround, I don't know if there are any plans to fix this. |
hi @pockets3407 and @twsouthwick , i still unable to get access of session from blazor app. Could please have a look in my Proram.cs file. in Controller i can getting the values. but in blazor it always return null. Proram.cs ====================== using BlazorTestCore.Components; var builder = WebApplication.CreateBuilder(args); builder.Services.AddHttpForwarder(); builder.Services.AddSystemWebAdapters() // Add services to the container. builder.Services.AddRazorComponents() var app = builder.Build(); if (!app.Environment.IsDevelopment()) app.UseHttpsRedirection(); //app.UseRouting(); app.UseAntiforgery(); //app.UseAuthorization(); app.UseWhen( //app.MapDefaultControllerRoute() app.MapRazorComponents() app.MapForwarder("/{**catch-all}", app.Configuration["ProxyTo"]).Add(static builder => ((RouteEndpointBuilder)builder).Order = int.MaxValue); app.Run(); Proram.cs end ====================== Blazor component============ @code {
} Thanks |
@erpardeepkaushik HttpContext is only available in static SSR. Try checking it when the page is pre-rendered in OnInitalizedAsync instead of the button click. If you need any session information after pre-rendering, I would take a look at: |
@pockets3407 thanks for a quick reply, I am using InteractiveServerRenderMode(prerender: false) so its null even on OnInitializedAsync , is there any way to add it in interactive SSR or InteractiveServerRenderMode(prerender: false) mode |
@erpardeepkaushik Take a look at the link I provided in my last post. HttpContext cannot be passed to interactive SSR, but the data can be retrieved before the circuit is opened and used. In my application, I am using PersistingApplicationState while pre-rendering to store the data I need |
I am getting below error on server, while the session access from webform app to razor page is working perfectly on local machine. any suggestion on this. sample code if (((System.Web.HttpContext)HttpContext).Session != null) Category: Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer Connection ID "16933543412991267053", Request ID "400010ee-0804-eb00-b63f-84710c7967bb": An unhandled exception was thrown by the application. Exception: |
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}"
}
}
}
}
}
The text was updated successfully, but these errors were encountered: