Keep Getting Error 404 No matter what I do

osyris 236 Reputation points
2021-11-27T18:01:25.773+00:00

I very Rarely get this problem but no matter what i do i keep getting error 404:

Asp net core LaunchSettings.json

  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:52277",
      "sslPort": 44378
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }


  },
    "Restaurant": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "https://localhost:7238;http://localhost:5238",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

the product Controller:

[Route("Product")]
    [ApiController]
    public class ProductController : ControllerBase
    {
        private ApplicationDbContext _dbContext;

        public ProductController(ApplicationDbContext dbContext)
        {
            _dbContext = dbContext;
        }

        [HttpGet]
        public async Task<IActionResult> GetProducts()
        {
            var prooduct = await _dbContext.products.ToListAsync();
            return Ok(prooduct);
        }

CLientSide angular

Service:

GetProducts(): Observable<any[]> {
  return this.http.get<any>("https://localhost:44378/Product");
}

Component:

AllProducts(){
    this.productService.GetProducts().subscribe(data =>{
  this.Products = data;

For people that are not familiar with Angular. the service is basicaly something that you can call inside of a component
so its better ordered. and in the component you call it. the "subscribe" activates the service call.

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,156 questions
{count} votes

1 answer

Sort by: Most helpful
  1. osyris 236 Reputation points
    2021-11-30T22:32:48.837+00:00

    Thank you for you reply,
    MeanWhile I have created a new project using he angular and asp net core template and updated angularto version 13

    But i still like to figure this out in case i need to add an already exisitng angular project

    I have changed the debug to IIS express
    when I go to the url i dont see anyhing it just rederects to LocalHost/(sslPort)

    I use asp net core 6 here is the program.cs

    using Microsoft.AspNetCore.Identity;
    using Microsoft.AspNetCore.SpaServices.AngularCli;
    using Microsoft.EntityFrameworkCore;
    using Restaurant.Data;
    using Restaurant.Model;
    
    var builder = WebApplication.CreateBuilder(args);
    
    // Add services to the container.
    
    builder.Services.AddDbContext<ApplicationDbContext>(options =>
    options.UseSqlServer(builder.Configuration.GetConnectionString("Database")));
    
    builder.Services.AddIdentity<ApplicationUser, ApplicationRole>()
        .AddEntityFrameworkStores<ApplicationDbContext>()
        .AddDefaultTokenProviders();
    
    builder.Services.AddControllers();
    builder.Services.AddSpaStaticFiles(configuration => 
    configuration.RootPath = "ClientApp/dist");
    
    var app = builder.Build();
    
    // Configure the HTTP request pipeline.
    if (!app.Environment.IsDevelopment())
    {
        app.UseExceptionHandler("/Error");
        // 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.UseRouting();
    
    app.UseAuthorization();
    
    app.UseSpa(spa =>
    {
        spa.Options.SourcePath = "ClientApp";
    
        if (app.Environment.IsDevelopment())
        {
            spa.UseAngularCliServer(npmScript: "start");
        }
    });
    app.Run();