Skip to content

Instantly share code, notes, and snippets.

@gavilanch
Created March 26, 2020 15:30
Show Gist options
  • Select an option

  • Save gavilanch/fbfb966b95191b861936e98d8c5b19ba to your computer and use it in GitHub Desktop.

Select an option

Save gavilanch/fbfb966b95191b861936e98d8c5b19ba to your computer and use it in GitHub Desktop.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.Use(async (context, next) =>
{
await next.Invoke();
if (context.Response.StatusCode == StatusCodes.Status401Unauthorized)
{
var customResponse = new { Code = "401", CustomMessage = "Maybe try logging in first!" };
await context.Response.WriteAsync(JsonConvert.SerializeObject(customResponse));
}
});
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment