Created
March 26, 2020 15:30
-
-
Save gavilanch/fbfb966b95191b861936e98d8c5b19ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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