Created
August 13, 2016 09:29
-
-
Save JamesRandall/314ac64a1cac7ecf21be4fe34e07a68f to your computer and use it in GitHub Desktop.
Redirect the root path of an Owin hosted application to the swagger end point
This file contains 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
using System.Net; | |
using Owin; | |
namespace MyApplication.Api.Extensions | |
{ | |
// ReSharper disable once InconsistentNaming | |
public static class IAppBuilderExtensions | |
{ | |
public static IAppBuilder RedirectRootToSwagger(this IAppBuilder app) | |
{ | |
app.Use(async (ctx, next) => | |
{ | |
if (ctx.Request.Path.Value == "/") | |
{ | |
ctx.Response.StatusCode = (int)HttpStatusCode.Redirect; | |
ctx.Response.Headers.Set("Location", ctx.Request.Uri + "swagger"); | |
} | |
else | |
{ | |
await next(); | |
} | |
}); | |
return app; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment