Blazor web app ASP core .net 8 Controller not finding route

How to use controllers in a blazor web app??? My route is not being found.
local host page con’t be found
file folder sctrucure

I have AddControllers and MapControllers in my program.cs

I want To be able to simple route to this controller so I can test how to download files, but I am unable to route to this controller when I type into the url.

I am not sure what I am missing or how to get the controller to be called. I have done the map and add controllers which has not brought anything.

using Microsoft.AspNetCore.Mvc;
using System.IO.Compression;

namespace SecureFileShare.Controllers
{
    public class HomeController : ControllerBase
    {
        [ApiController]
        [Route("api/[controller]")]
        public class FilesController : ControllerBase
        {
            private readonly IWebHostEnvironment _hostEnvironment;

            public FilesController(IWebHostEnvironment hostEnvironment)
            {
                _hostEnvironment = hostEnvironment;
            }

            [HttpGet]
            [Route("download-zip")]
            public IActionResult DownloadFiles()
            {
                try
                {
                    var folderPath = Path.Combine(_hostEnvironment.ContentRootPath, "FilesToDownload");

                    // Ensure the folder exists
                    if (!Directory.Exists(folderPath))
                        return NotFound("Folder not found.");

                    // Get a list of files in the folder
                    var files = Directory.GetFiles(folderPath);

                    if (files.Length == 0)
                        return NotFound("No files found to download.");

                    // Create a temporary memory stream to hold the zip archive
                    using (var memoryStream = new MemoryStream())
                    {
                        // Create a new zip archive
                        using (var zipArchive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
                        {
                            foreach (var file in files)
                            {
                                var fileInfo = new FileInfo(file);

                                // Create a new entry in the zip archive for each file
                                var entry = zipArchive.CreateEntry(fileInfo.Name);

                                // Write the file contents into the entry
                                using (var entryStream = entry.Open())
                                using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read))
                                {
                                    fileStream.CopyTo(entryStream);
                                }
                            }
                        }

                        memoryStream.Seek(0, SeekOrigin.Begin);

                        // Return the zip file as a byte array
                        return File(memoryStream.ToArray(), "application/zip", "files.zip");
                    }
                }
                catch (Exception ex)
                {
                    return StatusCode(500, $"An error occurred: {ex.Message}");
                }
            }
        }
    }
}

using SecureFileShare.Client.Pages;
using SecureFileShare.Components;

using Microsoft.AspNetCore.Authentication.Negotiate;
using Microsoft.AspNetCore.Components.Server.Circuits;
using Microsoft.Extensions.DependencyInjection.Extensions;
using SecureFileShare.Services;

var builder = WebApplication.CreateBuilder(args);


//For windows authentication 
//---------------------
//First add nuget package Microsoft.AspNetCore.Authentication.Negotiat
builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
   .AddNegotiate();

builder.Services.AddAuthorization(options =>
{
    options.FallbackPolicy = options.DefaultPolicy;
});

// Add services to the container.
builder.Services.AddRazorComponents()
    .AddInteractiveServerComponents()
    .AddInteractiveWebAssemblyComponents();

//Inject IHttpContextAccessor
builder.Services.AddHttpContextAccessor();

//injects
builder.Services.AddScoped<UserService>();
builder.Services.TryAddEnumerable(
    ServiceDescriptor.Scoped<CircuitHandler, UserCircuitHandler>());
//

builder.Services.AddControllers();  ///I ADDED CONTROLLER HERE
var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseWebAssemblyDebugging();
}
else
{
    app.UseExceptionHandler("/Error", createScopeForErrors: true);
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

app.UseHttpsRedirection();

app.UseStaticFiles();
app.UseAntiforgery();

///
app.UseAuthentication();
app.UseAuthorization();
///


app.MapRazorComponents<App>()
    .AddInteractiveServerRenderMode()
    .AddInteractiveWebAssemblyRenderMode()
    .AddAdditionalAssemblies(typeof(SecureFileShare.Client._Imports).Assembly);

app.MapControllers();   ///I MAPPED CONTROLLER HERE

app.Run();

New contributor

Quinn Nash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật