Check the docs before asking a question: How to use extended field query in EF query?, [Filter User list by new extra property #784](https://support.abp.io/QA/Questions/784/Filter-User-list-by-new-extra-property), How to add custom property to the user entity,Module Entity Extensions | Documentation Center | ABP.IO ...
- ABP Framework version: v8.0.2
- UI Type: Blazor WASM / Blazor Server
- Database System: EF Core (PostgreSQL)
Hi Support Teams,
I have two questions:
- Is there a way to use ScreenUrl within ExtraProperties instead of creating an additional ScreenUrl column and using EF.Property(u, "ScreenUrl") to write the query statement?
2. How can I add `context.GetHttpContext().Request.Headers["screen-url"]` to the `ScreenUrl` column in `EntityChanges`? Currently, when I run it, it only adds it to the `ScreenUrl` in `ExtraProperties` but doesn't save it to the newly added `ScreenUrl` column.
public class ExtendedAuditLogContributor : AuditLogContributor
{
public override void PreContribute(AuditLogContributionContext context)
{
context.AuditInfo.SetProperty(
"ScreenUrl",
context.GetHttpContext().Request.Headers["screen-url"]
);
}
public override void PostContribute(AuditLogContributionContext context)
{
var currentUser = context.ServiceProvider.GetRequiredService<ICurrentUser>();
foreach (var change in context.AuditInfo.EntityChanges)
{
change.SetProperty(
"ScreenUrl",
context.GetHttpContext().Request.Headers["screen-url"]);
change.SetProperty(
"UserId", currentUser.Id);
}
}
}
21 Answer(s)
-
0
Hi,
Is there a way to use ScreenUrl within ExtraProperties instead of creating an additional ScreenUrl column and using EF.Property(u, "ScreenUrl") to write the query statement?
Unfortunately no, It will be calculated on the client side instead of the server client, which will affect query performance: https://learn.microsoft.com/en-us/ef/core/querying/client-eval
How can I add
context.GetHttpContext().Request.Headers["screen-url"]to theScreenUrlcolumn inEntityChanges? Currently, when I run it, it only adds it to theScreenUrlinExtraPropertiesbut doesn't save it to the newly addedScreenUrlcolumn.Could you share a simple minimal project to reproduce the problem? I will check it, thanks. my email is shiwei.liang@volosoft.com
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
-
0Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
-
0
Hi,
I made some changes to the project and it works for me.
I have shared the project with you via email, you can check it
Steps
- Run
dotnet ef database updateto create database. (for authserver and httpapihost) - Run the AuthServer, HttpApi.Host and Blazor project
- Login and navigate to
commonpage - Click the
Create testbutton
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) - Run
-
0
It worked. Thank you very much.
But I'm still facing an issue. Currently, in Blazor WebAssembly, I have code in
HttpApi.Client.
and I use
context.GetHttpContext().Request.Headers["screen-url"].ToString();to get the URL.
However, using this approach won't work in Blazor Server. Is there any way to retrieve the URL when using Blazor Server?
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
Is the Blazor server a tiered solution?
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
I think it should be working.
How I reproduce the problem? I will check it.
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
-
0
You can try:
public class MyHubFilter : IHubFilter { public ValueTask<object?> InvokeMethodAsync(HubInvocationContext invocationContext, Func<HubInvocationContext, ValueTask<object?>> next) { var httpContext = invocationContext.Context.GetHttpContext(); if (httpContext != null) { var navigationManager = invocationContext.ServiceProvider.GetRequiredService<NavigationManager>(); httpContext.Request.Headers["screen-url"] = navigationManager.Uri; } return next(invocationContext); } } public override void PreConfigureServices(ServiceConfigurationContext context) { Configure<HubOptions>(options => { options.AddFilter<MyHubFilter>(); }); }Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
Please add to the Blazor server instead of HttpAPI project
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
Can you share a project?
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
You did not configure the
AuditMessageHandlerpublic override void PreConfigureServices(ServiceConfigurationContext context) { PreConfigure<AbpHttpClientBuilderOptions>(options => { options.ProxyClientBuildActions.Add((remoteServiceName, clientBuilder) => { clientBuilder.AddHttpMessageHandler<AuditMessageHandler>(); }); }); }Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
-
0
Hi,
Yes you need to make some changes
Idea from: https://stackoverflow.com/questions/77129117/blazor-navigationmanager-not-initialized-error
Add
AppInfoclass to Blazor server project.public class AppInfo : ISingletonDependency { public string? CurrentUrl { get; private set; } public void UpdateAppUrl(string url) { this.CurrentUrl = url; } }Move
AuditMessageHandlerclass to Blazor Server projectpublic class AuditMessageHandler : DelegatingHandler, ITransientDependency { private readonly AppInfo _appInfo; public AuditMessageHandler(AppInfo appInfo) { _appInfo = appInfo; } protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { request.Headers.Add("screen-url", _appInfo.CurrentUrl); return base.SendAsync(request, cancellationToken); } }Add
AppInfoProvider.razorto Blazor server project.@code { [Inject] private NavigationManager NavigationManager { get; set; } = default!; [Inject] private AppInfo AppInfo { get; set; } = default!; protected override void OnInitialized() { NavigationManager.LocationChanged += (sender, args) => { this.AppInfo.UpdateAppUrl(this.NavigationManager.Uri); }; } } ------------------- Configure<AbpLayoutHookOptions>(options => { options.Add(LayoutHooks.Body.First, typeof(AppInfoProvider),StandardLayouts.Application); });Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)



















