monolithic mvc project and adding OpenAPI

Newbie 26 Reputation points

Hi I'm a newbie, i have confusion about adding OpenAPI to empty MVC prj ("dotnet new mvc"), just tinkering around my thoughts, i'm able to success adding Swagger to controllers, appears SwaggerUI, doc... But when i run the app seems like web GUI not working anymore, maybe it's silly to do or think it like that way, or it's the problem of the codes i'm not modified properly,..
I would appreciate some help to explain it and point me at right direction.

A set of technologies in the .NET Framework for building web applications and XML web services.
4,118 questions
{count} vote

Accepted answer
  1. Zhi Lv - MSFT 32,006 Reputation points Microsoft Vendor

    Hi @Newbie ,

    GUI i mean the root URL=localhost:(port)/ not show anything after i adding swagger (localhost:port/swagger/index.html works fine) , im forget to check http code respond at the root "/" , i just want to know it's possible or not, thanks for your time.

    Have you ever solved the problem? If not, try to re-start the application and refer to the following steps:

    1. Run the following command to create an 6 MVC application.
      dotnet new mvc -o MvcSample: Creates a new ASP.NET Core MVC project in the MvcSample folder.
      code -r MvcSample: Loads the MvcSample.csproj project file in Visual Studio Code.
    2. Using the cd MvcSample command to go to the application folder.
    3. Run the following command to install the Swashbuckle:
      dotnet add MvcSample.csproj package Swashbuckle.AspNetCore -v 6.2.3.
    4. Add and configure Swagger middleware. After modifying, the program.cs file like this:
      var builder = WebApplication.CreateBuilder(args);  
      // Add services to the container.  
      // add service for API   
      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  
          name: "default",  
          pattern: "{controller=Home}/{action=Index}/{id?}");  
    5. Add API controller:
      using MvcSample.Models;  
      using Microsoft.AspNetCore.Authorization;  
      using Microsoft.AspNetCore.Mvc;  
      using System.Data;  
      using System.Text;  
      // For more information on enabling Web API for empty projects, visit  
      namespace MvcSample.Controllers  
          public class ToDoController : ControllerBase  
              // GET api/<ToDoController>/5  
              public string Get(int id)  
                  return "value";  
              // POST api/<ToDoController>  
              public void Post([FromBody] string value)  
              // PUT api/<ToDoController>/5  
              public void Put(int id, [FromForm] string value)  
              // DELETE api/<ToDoController>/5  
              public void Delete(int id)  
      Then, run the application using dotnet run command, and use browser to open the web app, the result as below: 236668-1.gif


    Get started with Swashbuckle and ASP.NET Core

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

0 additional answers

Sort by: Most helpful