One thing to note is that you're calling app.UseStaticFiles() twice, once before specifying the static files directory and once after.You only need to call it once.Additionally, ensure that the paths provided for static files are correct and accessible.
using FreeWebApplication.DataBase;
using
FreeWebApplication.OtherService;
using
FreeWebApplication.Repository;
using
Microsoft.AspNetCore.Server.Kestrel.Core;
using
Microsoft.EntityFrameworkCore;
using
Microsoft.Extensions.FileProviders;
var builder =
WebApplication.CreateBuilder(args);
builder.Services.AddControllersWithViews();
builder.Services.AddDbContext < APPDBContext > (option
=> option.UseSqlServer(builder.Configuration.GetConnectionString("DataConnectionString")));
builder.Services.AddScoped < StudentService > ();
builder.Services.AddScoped(typeof (IRepository <>), typeof (Repository <>));
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddMvc();
builder.Services.AddHttpContextAccessor();
builder.Services.Configure < KestrelServerOptions
> (options => {
options.Limits.MaxRequestBodySize = int.MaxValue;
});
builder.Services.AddDistributedMemoryCache();
builder.Services.AddSession(options => {
options.IdleTimeout =
TimeSpan.FromMinutes(1000);
});
var app = builder.Build();
if
(!app.Environment.IsDevelopment()) {
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new
PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot\Images")),
RequestPath = new PathString("/wwwroot/Images")
});
app.UseSession();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Student}/{action=Index}/{id?}");
app.Run();