Web APIs with VB.NET
ASP.NET Core can be used from VB for APIs (no Razor/Blazor). Use Microsoft.NET.Sdk.Web in the .vbproj.
Topics: model binding and validation (DataAnnotations), middleware, authentication/authorization (JWT bearer), CORS, problem details, versioning, rate limiting, health checks, OpenAPI.
Recommended for larger systems: a C# ASP.NET Core host (with better tooling and templates) referencing VB domain and service libraries.
Legacy: ASP.NET Web Forms / MVC 5 / Web API 2 (.NET Framework) fully support VB. Plan modernization (Module 49).
Imports Microsoft.AspNetCore.Builder
Imports Microsoft.AspNetCore.Http
Imports Microsoft.AspNetCore.Mvc
Imports Microsoft.Extensions.DependencyInjection
Module Program
Sub Main(args As String())
Dim builder = WebApplication.CreateBuilder(args)
builder.Services.AddControllers()
builder.Services.AddEndpointsApiExplorer()
builder.Services.AddSwaggerGen() ' Swashbuckle (or Microsoft.AspNetCore.OpenApi)
builder.Services.AddScoped(Of IProductService, ProductService)()
Dim app = builder.Build()
If app.Environment.IsDevelopment() Then
app.UseSwagger() : app.UseSwaggerUI()
End If
app.UseHttpsRedirection()
app.MapGet("/health", Function() Results.Ok(New With {.status = "ok"}))
app.MapControllers()
app.Run()
End Sub
End Module
<ApiController, Route("api/[controller]")>
Public Class ProductsController
Inherits ControllerBase
Private ReadOnly _svc As IProductService
Public Sub New(svc As IProductService)
_svc = svc
End Sub
<HttpGet("{id:int}")>
Public Async Function GetById(id As Integer) As Task(Of ActionResult(Of Produc
…