简体   繁体   中英

Using session state in ASP.NET Core 2.0 app in IFrame

I am creating a chat bot that lives inside an IFrame on clients' sites. The bot itself uses AJAX to communicate with the .NET Core 2 server.

The problem I have is that while the session is persisted as expected when running the chat bot on its own in a browser, running it in an IFrame causes a new session to be created on each request.

Now, the reason for this is that I am using a session cookie and most browsers do not like this approach when working with Iframes. The regular ASP.NET MVC solution would be to use sessionless cookies, but as with so many other landmines in .NET CORE, cookieless sessions are not supported.

So now I'm stuck and I don't know what to do.

Simple solution: Change a div's content using the AJAX information that is returned. Don't use Iframes at all. There is no requirement to use an iframe.

You only need to use an Iframe when the content returned is a full HTML page. Based on what you said you could just return the DIV content.

To maintain persistence, just set the initial DIV content to be the session state data when the page loads.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM