I followed the sample project bff react on our project. Our project is an asp core web application (8) with spa (react and vite). On local development environment it is working fine. After deploying project to folder homepage gives me HTTP 404 error.
Code changes on Program.cs
builder.Services.AddBff();
builder.Services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
options.DefaultSignOutScheme = OpenIdConnectDefaults.AuthenticationScheme;
}).AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
{
//strict SameSite Handling
options.Cookie.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Strict;
options.Cookie.Name = "__dmmService-bff";
}).AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>
{
options.Authority = iamAuthConfig.Authority;
options.ClientId = iamAuthConfig.ClientId;
options.ClientSecret = iamAuthConfig.ClientSecret;
options.ResponseType = OpenIdConnectResponseType.Code;
options.ResponseMode = OpenIdConnectResponseMode.Query;
options.GetClaimsFromUserInfoEndpoint = true;
options.MapInboundClaims = false;
options.SaveTokens = true;
options.DisableTelemetry = true;
options.Scope.Clear();
foreach (var scope in iamAuthConfig.Scopes.Split(" "))
{
options.Scope.Add(scope);
}
options.TokenValidationParameters = new()
{
NameClaimType = "name",
RoleClaimType = "role"
};
}).AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options =>
{
options.SaveToken = true;
})
builder.Services.AddAuthorizationBuilder().AddPolicy(....);
if (environment.IsDevelopment())
{
app.UseDefaultFiles();
app.UseStaticFiles();
}
//it was already there
app.UseRouting();
app.UseAuthentication();
//new added
app.UseBff();
//it was already there
app.UseAuthorization();
//new added
app.MapBffManagementEndpoints();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute().RequireAuthorization();
});
app.MapFallbackToFile("/index.html");
`
I followed the sample project bff react on our project. Our project is an asp core web application (8) with spa (react and vite). On local development environment it is working fine. After deploying project to folder homepage gives me HTTP 404 error.
Code changes on Program.cs
builder.Services.AddBff();
builder.Services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
options.DefaultSignOutScheme = OpenIdConnectDefaults.AuthenticationScheme;
}).AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
{
//strict SameSite Handling
options.Cookie.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Strict;
options.Cookie.Name = "__dmmService-bff";
}).AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>
{
options.Authority = iamAuthConfig.Authority;
options.ClientId = iamAuthConfig.ClientId;
options.ClientSecret = iamAuthConfig.ClientSecret;
options.ResponseType = OpenIdConnectResponseType.Code;
options.ResponseMode = OpenIdConnectResponseMode.Query;
options.GetClaimsFromUserInfoEndpoint = true;
options.MapInboundClaims = false;
options.SaveTokens = true;
options.DisableTelemetry = true;
options.Scope.Clear();
foreach (var scope in iamAuthConfig.Scopes.Split(" "))
{
options.Scope.Add(scope);
}
options.TokenValidationParameters = new()
{
NameClaimType = "name",
RoleClaimType = "role"
};
}).AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options =>
{
options.SaveToken = true;
})
builder.Services.AddAuthorizationBuilder().AddPolicy(....);
if (environment.IsDevelopment())
{
app.UseDefaultFiles();
app.UseStaticFiles();
}
//it was already there
app.UseRouting();
app.UseAuthentication();
//new added
app.UseBff();
//it was already there
app.UseAuthorization();
//new added
app.MapBffManagementEndpoints();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute().RequireAuthorization();
});
app.MapFallbackToFile("/index.html");
`
Share Improve this question asked Feb 4 at 10:10 Atahan CeylanAtahan Ceylan 1683 silver badges11 bronze badges2 Answers
Reset to default 0I changed the orders of middleware and deleted some unnecessary parts like app.MapFallbackToFile("/index.html"); Now it is working. Working Program.cs below:
builder.Services.AddBff();
builder.Services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
options.DefaultSignOutScheme = OpenIdConnectDefaults.AuthenticationScheme;
}).AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
{
//strict SameSite Handling
options.Cookie.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Strict;
options.Cookie.Name = "__dmmService-bff";
}).AddOpenIdConnect(OpenIdConnectDefaults.AuthenticationScheme, options =>
{
options.Authority = iamAuthConfig.Authority;
options.ClientId = iamAuthConfig.ClientId;
options.ClientSecret = iamAuthConfig.ClientSecret;
options.ResponseType = OpenIdConnectResponseType.Code;
options.ResponseMode = OpenIdConnectResponseMode.Query;
options.GetClaimsFromUserInfoEndpoint = true;
options.MapInboundClaims = false;
options.SaveTokens = true;
options.DisableTelemetry = true;
options.Scope.Clear();
foreach (var scope in iamAuthConfig.Scopes.Split(" "))
{
options.Scope.Add(scope);
}
options.TokenValidationParameters = new()
{
NameClaimType = "name",
RoleClaimType = "role"
};
}).AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options =>
{
options.SaveToken = true;
})
builder.Services.AddAuthorizationBuilder().AddPolicy(....);
app.UseBff();
app.MapBffManagementEndpoints();
You should change StaticFiles middlewares setting like below.
if (environment.IsDevelopment())
{
app.UseDefaultFiles();
app.UseStaticFiles();
}else{
app.UseDefaultFiles();
app.UseStaticFiles();
}
After deployment is complete, we need to ensure that the wwwroot
folder is included in the release file.