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

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

问题描述

我从基于Web表单的遗留应用程序引导Aurelia。我的身份验证相关信息在Custom Base Page类的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',窗口。 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天全站免登陆