I have a collection of Excel spreadsheets that I\'d like to serve in my ASP.NET 5 webapp only to authorized users.
This is a very simple example, but it can be changed to check for specific roles, and the code can be moved out of the Startup.cs for more flexibility.
app.Use(async (context, next) =>
{
if (!context.User.Identity.IsAuthenticated
&& context.Request.Path.StartsWithSegments("/excelfiles"))
{
throw new Exception("Not authenticated");
}
await next.Invoke();
});