C
C#17mo ago
int

✅ Respond with HTML instead of plaintext

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "<h1>Hello World!</h1>");

app.Run();
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "<h1>Hello World!</h1>");

app.Run();
This is my entire app right now - how do I make the entire app use HTML as the content type by default?
5 Replies
cap5lut
cap5lut17mo ago
int
intOP17mo ago
yeah but most of my app will return HTML responses wouldn't that be tiring to do for each one can i set a default for it
cap5lut
cap5lut17mo ago
the easiest would be to use something like MVC, razor pages or blazor. minimal apis is mainly designed for web apis
blueberriesiftheywerecats
Add middleware after creating app variable that making your response as html
app.Use(async (context, next) =>
{
context.Response.ContentType = "text/html";
await next(context);
});
app.Use(async (context, next) =>
{
context.Response.ContentType = "text/html";
await next(context);
});
Accord
Accord17mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server