How to share menu between ASP.net core applications

Asked

Viewed 39 times

-1

How to share menu between applications? We have several applications and all have the same menu, example:

Home | Beneficiary | Accredited

When new item appears we need to replicate in all applications. We try to use jquery.

<div id='idteste'></div> 
$('#idteste').load(/controle/action/)

When we do this we have the problem of CORS that would have to enable in MVC Core, even enabling CORS it gets css and js from the other site changing the current site, being second problem.

There is also the option to use < iframe > but I think there must be some other way to solve this problem of sharing menu only between applications.

  • If the problem are new items in the menu, why don’t you store these items/menu in the database and load them when the user accesses the system?

  • The problem of this is tbm style issue for example if you need to change color or font would have to do that in all others agree ?

  • I understood, I would make the menu items and the css/js to be loaded and added to the page dynamically, searching this data in an API, then you could have a pattern and customizations, but why enabling CORS and searching the menu in another application he changed the current site?

  • Yes it alters by doing with ajax, with API do not know how it would be or would

1 answer

1


You can solve the problem by dynamically loading the items and css/js from the menu:

Stores menu items in the database and in the user’s login you search them and store them in Sesssion or something so you don’t have to search every time the user navigates the application.

The css/js files in the menu should contain only the content referring to the menu and then you choose a project to host them, let’s say the original, and then you call the address of that original application in the other applications to load the file as for example we sometimes use the Cdn jquery

Example of jquery being searched externally:

<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>

In other projects you call css/js with the original address in src and href

<link rel="stylesheet" href="enderecoDoCssDoMenuDoSiteOriginal" />
<script src="enderecoDoJSDoMenuDoSiteOriginal"></script>

Remembering that you have to configure your project to allow access to only these two files or host them in a location that allows this, as your server and then all projects search the file there, and you change these files separately from the project

  • 1

    Thank you worked...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.