0

I'm making a custom tab app of MS Teams with ASP.NET, however, the tab doesn't seem to pass a same cookie between requests on MS Teams. So the ASP.NET app behind the tab generates a new Session.SessionID on every request.

I've checked the following question, and tried some settings according to that page, but nothing helped me. Actually my web site works nicely if I navigate it via Chrome or Edge.
ASP.NET: Session.SessionID changes between requests

How do I get a same cookie between requests on MS Teams?

Yoo Matsuo
  • 2,361
  • 2
  • 28
  • 41

1 Answers1

1

I've not tested this specifically so haven't seen it, but basically the broad idea of session is to have to uniquely "remember" a user, and then restore State for them from a location (e.g. database). From your question, it seems like the out of box "Session" object is giving trouble, but at any rate you should probably avoid using it because it won't "remember" the user even across devices.

However, Teams provides you a way to achieve the same thing yourself quite easily. Remember that the Teams 'Context' object provides a userObjectId property that is unique and valid for the same user on all sessions on all devices (it's actually their Azure Active Directory id). You can simply store whatever you want in your own database, key'ed by this id, and request it on page load. It's also possible to get this from the querystring for a static (personal) tab if you want to handle the behaviour server-side (e.g. C#).

Hilton Giesenow
  • 9,809
  • 2
  • 10
  • 24
  • Oh yeah, you are right. I didn't come up this approach, it seems promising. I want to accept your answer, however, I still want to know why a same cookie isn't sent to a server from Teams. So let me leave this question open for a bit more. Thanks anyway. – Yoo Matsuo Oct 28 '20 at 22:01
  • So that might be a more simple question than it seems - every time you go somewhere else in Teams, and then 'return' to a tab, Teams does a complete re-request of the Tab (it doesn't keep it around, I assume because it is worried the tab content could be stale and it has no way to know. Either that or because of memory footprint, or similar). Either way, it's a completely new request (i.e. a new session), and hence generates a new Session ID. – Hilton Giesenow Oct 29 '20 at 04:24
  • 1
    No, actually it happens on a same tab, not going back and forth to other tabs. So I load the web app on the teams tab, then navigate to another page which is in the web app. It should send a same cookie but the teams doesn't do it for some reason. I'm guessing SameSite setting might cause this issue, but not sure. I'll dig into this setting more when I have a time though. – Yoo Matsuo Oct 29 '20 at 12:34
  • ohh, I see. Yes, that's definitely not what I'd expect! – Hilton Giesenow Oct 29 '20 at 13:05