|
1 | 1 | // Licensed to the .NET Foundation under one or more agreements.
|
2 | 2 | // The .NET Foundation licenses this file to you under the MIT license.
|
3 | 3 |
|
4 |
| -using System; |
5 |
| -using System.Collections.Generic; |
6 |
| -using System.IO; |
7 |
| -using System.Linq; |
8 | 4 | using Microsoft.AspNetCore.Authentication.Cookies;
|
9 | 5 | using Microsoft.AspNetCore.Authorization;
|
10 |
| -using Microsoft.AspNetCore.Builder; |
11 |
| -using Microsoft.AspNetCore.Hosting; |
12 |
| -using Microsoft.AspNetCore.Http; |
13 |
| -using Microsoft.AspNetCore.Mvc; |
14 |
| -using Microsoft.Extensions.Configuration; |
15 |
| -using Microsoft.Extensions.DependencyInjection; |
16 | 6 | using Microsoft.Extensions.FileProviders;
|
17 |
| -using Microsoft.Extensions.Hosting; |
18 | 7 |
|
19 | 8 | namespace StaticFilesAuth;
|
20 | 9 |
|
@@ -53,7 +42,7 @@ public void ConfigureServices(IServiceCollection services)
|
53 | 42 | {
|
54 | 43 | return false;
|
55 | 44 | }
|
56 |
| - if (context.Resource is Endpoint endpoint) |
| 45 | + if (context.Resource is HttpContext httpContext && httpContext.GetEndpoint() is Endpoint endpoint) |
57 | 46 | {
|
58 | 47 | var userPath = Path.Combine(usersPath, userName);
|
59 | 48 |
|
@@ -134,12 +123,14 @@ private static void SetFileEndpoint(HttpContext context, PhysicalFileProvider fi
|
134 | 123 | var fileSystemPath = GetFileSystemPath(files, context.Request.Path);
|
135 | 124 | if (fileSystemPath != null)
|
136 | 125 | {
|
137 |
| - var metadata = new List<object>(); |
138 |
| - metadata.Add(new DirectoryInfo(Path.GetDirectoryName(fileSystemPath))); |
139 |
| - metadata.Add(new AuthorizeAttribute(policy)); |
| 126 | + var metadata = new List<object> |
| 127 | + { |
| 128 | + new DirectoryInfo(Path.GetDirectoryName(fileSystemPath)), |
| 129 | + new AuthorizeAttribute(policy) |
| 130 | + }; |
140 | 131 |
|
141 | 132 | var endpoint = new Endpoint(
|
142 |
| - c => throw new InvalidOperationException("Static file middleware should return file request."), |
| 133 | + requestDelegate: null, |
143 | 134 | new EndpointMetadataCollection(metadata),
|
144 | 135 | context.Request.Path);
|
145 | 136 |
|
|
0 commit comments