0

I'll start by mentioning I'm new to angular and I'm new to ASP.NET. I am working on a web app that combines pdf documents into one pdf document. The tool is an angular front end and ASP.NET core back end, and it should support multiple browsers at the same time.

I have got a functioning version of the web app already going, but without the support for multiple browsers. It works as follows:

  1. Submit pdf 1 through the angular app, that posts the pdf to the asp.net backend controller. The backend stores the pdf in a service (singleton service).

  2. Submit pdf 2 through angular app, that posts the pdf to asp.net backend controller which stores pdf in service

  3. Click Combine button in angular app, which posts a request to backend to combine the pdfs it has into 1, and return the newly created pdf to the angular app.

Obviously, the problem here is that I use a singleton service to persist data for the browser: If I submitted pdf1 through one browser, and then loaded up another browser and submit pdf2, and load up another browser and click the combine button, it will combine pdf 1 and 2 - which is obviously not right!

I've been looking into using session data to store the individual pdfs, but ran into a problem in that using session data in SPA applications is not advisable, and with web api is code smell. So I'm wondering what the correct way to tackle this problem is so I can go away and read up on it! How do I go about storing data per user / per browser temporarily in angular web app with asp.net backend...

1
  • use a combination of sessionID + startsession_timestamp to identify the PDF uploader browser/browsertab Commented Apr 6, 2022 at 14:36

1 Answer 1

1

I would move away from the singleton having any awareness of session/users/documents/etc and just do activities; it should be pretty stateless.

I am guessing you are persisting them in memory, which is what you mean by in the service, and that can also get tricky. Scaling could become an issue very quickly.

Perhaps there is a technical and UI solution to this? Could you persist the PDFs in a datastore, and then choose which to combine from those in the database in a separate view or page? This would be the cleanest from a data perspective.

However, if you are deadset on the same view and that view/session only being aware of what has been uploaded in that session, you would need to use some sort of identifier as J.Salas mentioned. I would still vote for moving away from storing the documents in memory, but the solution here wouldn't care either way. You can prepend the pdf identifier stored with the session ID and you know which is attached to which.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the response. Yes, I am persisting in memory and I'm aware that scaling could become an issue. I have been debating whether to persist the PDFs directly into a database, but I'd like to throw the data away when the user's session expires as well. There is no reason to keep all this data lying around
Certainly plenty of mechanisms to clear out data when a session expires or just an amount of time if that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.