How to embed asp.net mvc app into CORS website - we used IFRAME before

camos.ms 21 Reputation points
2021-07-26T08:55:29.593+00:00

Hi together,

We are working on an asp.net mvc (.net framework version 4.8) application that serves a HTML frontend for our companies' backend process. The application start uses the POST-REDIRECT-GET pattern. Later on, XMLHttpRequest exchanging Json data in both directions.

Today the app either occupies the browsers whole window or is embedded into an IFRAME. When running in IFRAME, the domains are in no relation so CORS comes into play.

Starting with Safari 13, the IFRAME solution stopped working on apple devices. Reason for that is that Safari 13 (ff) blocks CORS cookies in IFRAME and the SessionID is not transmitted back: the IFRAME sends the initial startup request, the asp.net answers the starting page and a "Set-Cookie: SessionID=xyz" HTTP header. But later, safari will not reply this SessionID with succeeding HTTP requests and so the mvc app is not working.

On the other hand, some of our customers complained before, that the IFRAME technology is outdated and we need to change to modern technology. Therefore, we want to change to maybe WebComponent and ShadowDOM.

However, in this scenario, I got exactly the same problem. The outer page runs in domain 'a.org' and executes a <custom-frontend> HTML instruction. This attaches a shadow DOM and connects to the asp.net running in domain 'b.com' server via XMLHttpRequest. To my knowledge, the only way to communicate with the asp.net is XMLHttpRequest (or the fetch API - which, to my knowledge, has no conceptional benefit).

I found no way to enforce the browser to extract the SessionID cookie from the initial request and use it in later XMLHttpRequest requests.

In addition, this problem is significant for other cookies too. Our application is used to run in HA load balanced environments: OSI level 7 load balancer are adding cookies too. I think they will not operate either.

Do you have any solution or hint, which direction I should investigate into?

Any help is highly appreciated.
Thank you in advance.

Developer technologies | ASP.NET | Other
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 77,766 Reputation points Volunteer Moderator
    2021-07-26T14:57:48.973+00:00

    Instead of cookies you should use bearer tokens, typically jwt tokens. This is easier with a SPA like app, but you could use session storage to do a MPA.


1 additional answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,766 Reputation points Volunteer Moderator
    2021-07-27T15:51:35.02+00:00

    it depends on needs. There are oauth/jwt client libraries for javascript. It is common to store the refresh token in local storage. you can use fetch, jquery or axios to pass the bearer token, its just a header.

    how do users authenticate now? is it a login page? are you going to switch to a SPA type app? These answer will determine how the client script get the token, and how it needs to be stored locally.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.