Adding Web Api Controller to a Razor Page ASP.NET Core app
jicking bebiro

jicking bebiro @jicking

Joined:
Oct 4, 2019

Adding Web Api Controller to a Razor Page ASP.NET Core app

Publish Date: Aug 28 '21
3 0

This is part of a personal ASP.NET Core cookbook that i am working on.

Open an existing asp.net core 5 razor pages app.

Add Swashbuckle.AspNetCore via nugget. This will auto generate api docs, cool right?
image

Update Startup.cs to include controller and swagger services and middlewares.
image

At project root, add Controllers directory then open context menu under that folder by selecting the folder and right click.
On context menu, click add > controller

A new dialog window will open for scaffolding options.
Select API.
image

Run project then go to https://localhost:PORT/swagger
image

There you have it, happy hacking.

Comments 0 total

    Add comment