How to pass data from ASP.NET WebForms to Aurelia Global Scope

前端 未结 1 1492
自闭症患者
自闭症患者 2021-01-03 02:58

I am bootstrapping Aurelia from a Web-forms based legacy application. My authentication related information is maintained in the web-forms application in the Custom Base Pag

相关标签:
1条回答
  • 2021-01-03 03:23

    You could put logic your custom base page to add a <script> tag to the head of the document that makes all the information available to javascript applications:

    <head>
      ...
      <script>
        window.appInfo = {
          user: 'foo',
          bar: 'baz'
        };
      </script>
    </head>
    <body aurelia-app="main">
      ...
    

    Then in your aurelia app you can access this info as needed:

    export class App {
      constructor() {
        let info = window.appInfo;
        // do something with the app info...
      }
      ...
    }
    

    You could even register the object in the container, enabling you to declare it as a dependency. This will make your code more portable and testable.

    In main.js: aurelia.container.registerInstance('app-info', window.appInfo);

    @inject('app-info')
    export class App {
      constructor(info) {
        // do something with the app info...         
      }
      ...
    }
    
    0 讨论(0)
提交回复
热议问题