Hi @Marján Zoltán
Please check the SystemWebAdapters
package version and your project version. From this issue, it seems that if using SystemWebAdapters 1.3.0
and .Net 8
, System.Web.HttpContext.Session might be null. You can check your application and package version and try to use the 1.2 version on .NET 6.
I also tried to use the SystemWebAdapters
package to share the session, but all failed, not matter setting session in Session_Start
or controller. I suggest you can also post this issue on SystemWebAdapters Forum, and let the SystemWebAdapters team member give some suggestion.
To share session between ASP.NET and .NET CORE application, there have a workaround to share session value via cookie, you can refer to it:
Code in ASP.NET Controller:
public ActionResult Index()
{
var sessionValue = "JohnDoe";
// Store a value in the session
Session["UserName"] = "JohnDoe";
// In a controller or action in the MVC app
var cookie = new HttpCookie("SharedSession", sessionValue)
{
HttpOnly = true, // Secure it to prevent client-side JavaScript access
Expires = DateTime.Now.AddMinutes(30), // Set expiration for the session
Domain = "localhost" // Set to the shared domain for subdomains
};
Response.Cookies.Add(cookie);
ViewBag.UserName = sessionValue;
return View();
}
In ASP.NET Core Application:
public IActionResult Index()
{
var sharedSession = Request.Cookies["SharedSession"];
if (sharedSession != null)
{
// Use the session value
var sessionValue = sharedSession;
ViewBag.UserName = sessionValue;
}
return View();
}
Note: In this workaround, the cookies should in the same domain. Refer to this article: Share authentication cookies among ASP.NET apps
Besides, you can also database or Redis to share data between ASP.NET and .NET CORE application.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion