【问题标题】:How to get current user id on Angular and Asp.Net Boilerplate?如何在 Angular 和 Asp.Net Boilerplate 上获取当前用户 ID?
【发布时间】:2018-12-21 12:17:17
【问题描述】:

有什么方法可以使用 Angular + Asp.Net Boilerplate 让当前用户使用 Angular?

我知道我可以通过 API 获得它。但我想使用当前用户 ID 将对象发送到 API。

【问题讨论】:

  • 你能展示一些你迄今为止尝试过的代码示例吗?
  • 在角度上我没有尝试过任何东西,因为我找不到那里是否存在我可以管理当前用户的服务。
  • 发布您的更新作为答案,而不是将其放在您的问题中。
  • @Testador 将您的更新作为答案发布,而不是将其放在您的问题中。

标签: c# angular aspnetboilerplate asp.net-boilerplate


【解决方案1】:

更新

我找到了一个可以获取用户信息的服务。

@Injectable()
export class AppSessionService {

    private _user: UserLoginInfoDto;
    private _tenant: TenantLoginInfoDto;
    private _application: ApplicationInfoDto;

    constructor(
        private _sessionService: SessionServiceProxy,
        private _abpMultiTenancyService: AbpMultiTenancyService) {
    }

    get application(): ApplicationInfoDto {
        return this._application;
    }

    get user(): UserLoginInfoDto {
        return this._user;
    }

    get userId(): number {
        return this.user ? this.user.id : null;
    }

    get tenant(): TenantLoginInfoDto {
        return this._tenant;
    }

    get tenantId(): number {
        return this.tenant ? this.tenant.id : null;
    }
}

【讨论】:

    【解决方案2】:

    在角度声明 UserLoginInfoDto 类的对象。 用 this.appSession.user 初始化对象值 导入 UserLoginInfoDto 类。 例如:

    userLogInInfo: UserLoginInfoDto;
    

    在内容或视图初始化中

    this.userLogInInfo = this.appSession.user;
    

    【讨论】:

    • 我不能只在我的组件上注入 AppSessionService 吗?
    猜你喜欢
    • 1970-01-01
    • 2015-05-12
    • 2022-09-24
    • 2012-10-20
    • 2014-05-02
    • 2015-08-22
    • 1970-01-01
    • 2018-10-03
    • 1970-01-01
    相关资源
    最近更新 更多