如何将数据从 ASP.NET WebForms 传递到 Aurelia Global Scope [英] How to pass data from ASP.NET WebForms to Aurelia Global Scope

查看:26
本文介绍了如何将数据从 ASP.NET WebForms 传递到 Aurelia Global Scope的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从基于 Web 表单的遗留应用程序引导 Aurelia.我的身份验证相关信息保存在自定义基页类中的 Web 表单应用程序中.

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 Page class.

我如何通过&将此身份验证信息维护到 Aurelia 的全局范围?这样我就可以在使用路由构建菜单时使用它来根据用户/角色显示/隐藏某些菜单项?

How do I pass & maintain this authentication information to Aurelia's global scope? So that I can use it while building the menus using routes to show/hide certain menu items based on the user/role?

推荐答案

您可以将逻辑置于您的自定义基页中,以将 <script> 标记添加到文档的头部,使所有javascript 应用程序可用的信息:

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">
  ...

然后在您的 aurelia 应用程序中,您可以根据需要访问此信息:

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.

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

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

@inject('app-info')
export class App {
  constructor(info) {
    // do something with the app info...         
  }
  ...
}

这篇关于如何将数据从 ASP.NET WebForms 传递到 Aurelia Global Scope的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆