I am building a Blazor Server web app because I want to avoid the added complexity of a WASM app for now. With the razorformat pages, there was a property, Gateway, that would allow you to call other services from within the .cshtml page. However I can’t find something similar for .razor pages. So I am currently injecting a Gateway when configuring the AppHost:
services.AddSingleton(GetServiceGateway());
This works mostly without issue, however there seems to be an issue in conjunction with AutoApply userauth properties. When I try to create a new record, this error shows in the console:
Error in GetSession() when ApplyPreAuthenticateFilters
System.NullReferenceException: Object reference not set to an instance of an object.
at ServiceStack.Auth.NetCoreIdentityAuthProvider.PreAuthenticateAsync(IRequest req, IResponse res) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/Auth/NetCoreIdentityAuthProvider.cs:line 114
at ServiceStack.ServiceStackHost.ApplyPreAuthenticateFiltersAsync(IRequest httpReq, IResponse httpRes) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/ServiceStackHost.Runtime.cs:line 86
at ServiceStack.ServiceExtensions.GetSessionInternalAsync(IRequest httpReq, Boolean reload, Boolean async, CancellationToken token) in /home/runner/work/ServiceStack/ServiceStack/ServiceStack/src/ServiceStack/ServiceExtensions.cs:line 235
The record will be created, but CreatedBy string is null. Below an excerpt of my audit filter
else if (meta.HasAutoApply(Behavior.AuditCreate))
{
meta.Add(new AutoPopulateAttribute(nameof(AuditBase.DateCreated)) {
Eval = "now", NoCache = true
});
meta.Add(new AutoPopulateAttribute(nameof(AuditBase.CreatedBy)) {
Eval = "userAuthName", NoCache = true
});
}
Here is the auditbase and the dto
public class CustomerCallEventNote:AuditBase
{
[AutoIncrement]
public int Id { get; set; }
[References(typeof(CustomerCallEvent))]
public int CustomerCallEventId { get; set; }
public string Text { get; set; }
}
public abstract class AuditBase
{
[DataMember(Order = 1), Required]
public DateTime DateCreated { get; set; }
[DataMember(Order = 2)]
public string CreatedBy { get; set; }
[DataMember(Order = 3)]
public DateTime? DateModified { get; set; }
[DataMember(Order = 4)]
public string ModifiedBy { get; set; }
[DataMember(Order = 5), Index] //Check if Deleted
public DateTime? DateDeleted { get; set; }
[DataMember(Order = 6)]
public string DeletedBy { get; set; }
}
I am using MicrosoftGraphProvider for authentication however is happens when I log in as the admin as well. When I use the locode ui to create records, the createdby field gets populated correctly.