小编JH-*_*Ren的帖子

当我无权访问 HttpContext 时,如何填充我的审计日志 UserId 字段?

我有一个包含两个项目的解决方案,我的 API 层和我的数据层。

数据层使用实体框架,不了解ASP.NET WebApi。

API 层使用 ASP.NET WebApi。

我计划使用 Audit.NET 来审核记录更改。

目前,我已经在我的 API 项目中安装了 Audit.NET、Audit.EntityFramework 和 Audit.WebApi。

我希望使用审计过滤器属性。( config.Filters.Add(new AuditApiAttribute());)

我的问题是,当我要填充 EntityLog 对象时,我还想用当前执行授权操作的用户的 ID 填充 UserId 字段,如果操作是匿名的,则为 null。

作为我的 Startup.cs 的一部分,我运行这个函数来配置 Audit.NET:

private void ConfigureAudit()
        {
            Audit.Core.Configuration.Setup()
                .UseEntityFramework(x => x
                    .AuditTypeMapper(t => typeof(AuditLog))
                    .AuditEntityAction<AuditLog>((ev, entry, entity) =>
                    {
                        entity.UserId = ???;
                        // other fields...
                    })
                    .IgnoreMatchedProperties()
                );
        }
Run Code Online (Sandbox Code Playgroud)

显然,此时我无法使用,HttpContext.Current.User.Identity.GetUserId()因为我不在控制器内,而且我没有看到将 UserId 传递到 Audit 事件的方法。

此时如何检索 UserId?

c# entity-framework audit.net

5
推荐指数
1
解决办法
1382
查看次数

Ngrx 效果中的“never”类型不存在属性

我正在使用 Angular 8 和 NGRX 8。我有一个操作:

export const loadEnvironment = createAction(
  LicencingActionTypes.LoadEnvironment,
  props<{environment: Environment}>()
);
Run Code Online (Sandbox Code Playgroud)

以及相应的效果:

 loadEnvironment = createEffect(() => this.actions$.pipe(
    ofType(LicencingActionTypes.LoadEnvironment),
    exhaustMap((action) =>
      this.authService.
      getToken(LicencingEffects.getAuthDetailsForEnvironment(action.environment))
        .pipe(
          switchMap((token) => [
            AuthActions.onLogin({token: token}),
            LicencingActions.onLoadEnvironment({environment: action.environment})
          ]),
          catchError(error => of(AuthActions.onLoginError({error: error})))
        )
    )
  ));
Run Code Online (Sandbox Code Playgroud)

我一直在阅读 NGRX 8 的文档(https://ngrx.io/guide/effects#incorporating-state)。

他们的示例表明您可以只使用操作属性而不强制转换操作的类型:

...
exhaustMap(action =>
        this.authService.login(action.credentials)
...
Run Code Online (Sandbox Code Playgroud)

Webpack 无法编译,并且出现以下错误:

ERROR in src/app/licencing/effects/licencing.effects.ts(20,69): error TS2339: Property 'environment' does not exist on type 'never'.
Run Code Online (Sandbox Code Playgroud)

突出显示错误的代码屏幕截图

我哪里错了?

ngrx-effects angular8

2
推荐指数
1
解决办法
1796
查看次数

错误:无法解析 ProductsEffects 的所有参数:(?, ?)

我正在运行 Angular 9、@ngrx/storev9 和 SSR,但我只是npm start在开发中运行,所以 SSR 并不是真正的因素。

我刚刚添加了 NGRX Store 并为某些产品制作了我的动作、减速器和效果。运行此命令后,我现在收到错误:Error: Can't resolve all parameters for ProductsEffects: (?, ?).

ProductsEffects类构造函数如下:

constructor(private actions$: Actions<ProductsActions>,
            private appService: AppService) {
}
Run Code Online (Sandbox Code Playgroud)

AppService 类标记为@Injectable({providedIn: 'root'}),并且actions$应该从 NGRX Store 注入。

这是来自的导入部分app.module


const EFFECTS = [ProductsEffects];

...

imports: [
        BrowserModule.withServerTransition({appId: 'my-app'}),
        BrowserAnimationsModule,
        HttpClientModule,
        NgxSpinnerModule,
        AgmCoreModule.forRoot({
            apiKey: 'redacted'
        }),
        SharedModule,
        routing,
        StoreModule.forRoot(reducers, {
            metaReducers,
            runtimeChecks: {
                strictStateImmutability: true,
                strictActionImmutability: true
            }
        }),
        EffectsModule.forRoot(EFFECTS),
        StoreRouterConnectingModule.forRoot()
    ],
Run Code Online (Sandbox Code Playgroud)

以下是相关部分 …

ngrx-effects angular ngrx-store

1
推荐指数
1
解决办法
1082
查看次数