我有一个使用aspnetboilerplate.com的ASP.NET CORE Web应用程序。它在本地运行良好,但是此例外发生在已发布的版本中:
Abp.AbpException:未知的过滤器名称:MayHaveTenant。确保此过滤器之前已注册。
最后,此异常导致客户端502错误:
502-Web服务器在充当网关或代理服务器时收到无效响应。
我在此应用程序中未使用多租户。我最近看到此异常,但之前效果很好。
我试图注册MayHaveTenant过滤器,但是该注册已被注册。我跟踪了失败的请求,但是没有有用的信息。谁能帮我解决这个问题?
更新
这是我的堆栈跟踪:
Abp.AbpException: Unknown filter name: MayHaveTenant. Be sure this filter is registered before.
at Abp.Domain.Uow.UnitOfWorkBase.GetFilterIndex(String filterName)
at Abp.Domain.Uow.UnitOfWorkBase.SetFilterParameter(String filterName, String parameterName, Object value)
at Abp.Domain.Uow.UnitOfWorkBase.SetTenantId(Nullable`1 tenantId, Boolean switchMustHaveTenantEnableDisable)
at Abp.Domain.Uow.UnitOfWorkBase.Begin(UnitOfWorkOptions options)
at Abp.Domain.Uow.UnitOfWorkManager.Begin(UnitOfWorkOptions options)
at Abp.Auditing.AuditingHelper.SaveAsync(AuditInfo auditInfo)
at Abp.AspNetCore.Mvc.Auditing.AbpAuditActionFilter.OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ExceptionContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
at MyProject.Authentication.JwtBearer.JwtTokenMiddleware.<>c__DisplayClass0_0.<<UseJwtTokenMiddleware>b__0>d.MoveNext() in H:\MyProject\src\MyProject.Web.Core\Authentication\JwtBearer\JwtTokenMiddleware.cs:line 22
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext context)
这是我的DbContext:
public class MyProjectDbContext : AbpZeroDbContext<Tenant, Role, User, MyProjectDbContext>
{
/* Define a DbSet for each entity of the application */
public DbSet<Category> Categories { get; set; }
public DbSet<Provider> Providers { get; set; }
public DbSet<Product> Products { get; set; }
public DbSet<Property> Properties { get; set; }
public DbSet<ProductProperty> ProductProperties { get; set; }
public DbSet<Stock> Stocks { get; set; }
public DbSet<ProductPicture> ProductPictures { get; set; }
public DbSet<Comment> Comments { get; set; }
public DbSet<Score> Scores { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<OrderItem> OrderItems { get; set; }
public DbSet<Privilege> Privileges { get; set; }
public MyProjectDbContext(DbContextOptions<MyProjectDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfiguration(new CategoryConfiguration());
modelBuilder.ApplyConfiguration(new OrderConfiguration());
modelBuilder.ApplyConfiguration(new StockConfiguration());
base.OnModelCreating(modelBuilder);
}
}
答案 0 :(得分:1)
对我来说,此错误是在将asp.net核心样板项目部署到其他服务器后发生的。
连接字符串有问题。由于这个误导性的错误,我浪费了数小时并最终修复了它。如果有人也得到这样的错误。确保首先检查连接字符串。谢谢
答案 1 :(得分:0)
如果您覆盖了DbContext的OnModelCreating或Initialize方法,而不是称为基本方法,则会发生。