What does this actually mean, been fighting it for hours and can't figure out what its complaining about
InvalidOperationException: Endpoint / (/) contains anti-fery metadata, but a middleware was not found that supports anti-fery. Configure your application startup by adding app.UseAntifery() in the application startup code. If there are calls to app.UseRouting() and app.UseEndpoints(...), the call to app.UseAntifery() must go between them. Calls to app.UseAntifery() must be placed after calls to app.UseAuthentication() and app.UseAuthorization().
I run it locally in debug and it works absoloutely fine but when I do a dotnet publish
and then run the app via command line, it fails to load the page with the above error.
This is my program.cs
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Mvc;
using MudBlazor.Services;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using System.Text.Json.Serialization;
var builder = WebApplication.CreateBuilder(args);
// Add MudBlazor services
builder.Services.AddMudServices();
// Add services to the container.
builder.Services
.AddRazorComponents()
.AddInteractiveWebAssemblyComponents();
builder.Services
.AddControllers()
.AddJsonOptions(opts =>
{
opts.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
opts.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
});
var app = builder.Build();
if (builder.Environment.IsDevelopment())
{
app.UseWebAssemblyDebugging();
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseAntifery();
app.UseEndpoints(e => e.MapControllers());
app.UseHttpsRedirection();
app.UseStaticFiles();
app.MapRazorComponents<App>()
.AddInteractiveWebAssemblyRenderMode()
.AddAdditionalAssemblies(typeof(Foo.Bar.WebClient._Imports).Assembly);
app.UsePathBase("/foo/bar");
await app.RunAsync();
What does this actually mean, been fighting it for hours and can't figure out what its complaining about
InvalidOperationException: Endpoint / (/) contains anti-fery metadata, but a middleware was not found that supports anti-fery. Configure your application startup by adding app.UseAntifery() in the application startup code. If there are calls to app.UseRouting() and app.UseEndpoints(...), the call to app.UseAntifery() must go between them. Calls to app.UseAntifery() must be placed after calls to app.UseAuthentication() and app.UseAuthorization().
I run it locally in debug and it works absoloutely fine but when I do a dotnet publish
and then run the app via command line, it fails to load the page with the above error.
This is my program.cs
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Mvc;
using MudBlazor.Services;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using System.Text.Json.Serialization;
var builder = WebApplication.CreateBuilder(args);
// Add MudBlazor services
builder.Services.AddMudServices();
// Add services to the container.
builder.Services
.AddRazorComponents()
.AddInteractiveWebAssemblyComponents();
builder.Services
.AddControllers()
.AddJsonOptions(opts =>
{
opts.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
opts.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
});
var app = builder.Build();
if (builder.Environment.IsDevelopment())
{
app.UseWebAssemblyDebugging();
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseAntifery();
app.UseEndpoints(e => e.MapControllers());
app.UseHttpsRedirection();
app.UseStaticFiles();
app.MapRazorComponents<App>()
.AddInteractiveWebAssemblyRenderMode()
.AddAdditionalAssemblies(typeof(Foo.Bar.WebClient._Imports).Assembly);
app.UsePathBase("/foo/bar");
await app.RunAsync();
Share
Improve this question
edited 9 hours ago
Zhi Lv
21.5k1 gold badge27 silver badges37 bronze badges
asked yesterday
Dr SchizoDr Schizo
4,3647 gold badges45 silver badges87 bronze badges
1 Answer
Reset to default 0put the middleware app.UseHttpsRedirection();
before app.UseRouting();
As stated in the document:
UseAntifery is called after UseHttpsRedirection. A call to UseAntifery must be placed after calls, if present, to UseAuthentication and UseAuthorization.