I am using ASP.NET core 6 and i created my application with the react option ( so i have a ClientApp in my folder).
When i run the application, i will see my react UI and unable to see the swagger UI.
Usually when u choose to build frontend
and backend
from two different folder, you will see the swagger UI if u run the backend on visual studio.
BUT right now i only see my react app UI. I am trying to access the swagger with https://localhost:44434/swagger
or https://localhost:44434/swagger/index.html
but it just stays on my react app UI page.
This is the video i followed to try to set it up :
https://www.youtube.com/watch?v=RvwvFmO-56E
Any idea ? Thanks a lot !
This is my program.cs
code :
using BugTracker.Context;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
// 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.UseSwagger();
app.UseSwaggerUI();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
app.MapFallbackToFile("index.html"); ;
app.Run();
This is my controller code :
using Microsoft.AspNetCore.Mvc;
using System;
namespace BugTracker.Controllers
{
[ApiController]
[Route("api/authentication")]
public class AuthController : Controller
{
[HttpGet]
public IActionResult Test()
{
return Ok("success");
}
}
}
Swashbuckle.AspNetCore
, and then inProgram.cs
I addedbuilder.Services.AddSwaggerGen();
andapp.UseSwagger(); app.UseSwaggerUI();
, then after running the application, visitinghttps://localhost:port/swagger/index.html
, I can see Swagger Ui – Brownout