Martin McMahon
Martin McMahon

Reputation: 333

Custom HTTP headers in Razor Pages

I need to add a custom http request header in a razor pages app. I know it used to be possible to do this with customHeaders in web.config but since we know longer have a web.config file I can't see a way to do this. Is there an equivalent way yo add?

Upvotes: 1

Views: 2602

Answers (1)

Mick
Mick

Reputation: 114

It looks like you can add code to startup.cs to support. See link below

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
   app.Use(async (context, next) =>

      context.Response.Headers.Add("X-Content-Type-Options", "nosniff")
      await next.Invoke()
});

https://www.ceciliasharp.net/how-to-add-http-headers-to-asp-net/

Upvotes: 2

Related Questions