diff --git a/src/Middleware/Middleware.sln b/src/Middleware/Middleware.sln index 45b7e7757df4..d3087585f728 100644 --- a/src/Middleware/Middleware.sln +++ b/src/Middleware/Middleware.sln @@ -289,6 +289,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Reques EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.RequestThrottling.Tests", "RequestThrottling\test\Microsoft.AspNetCore.RequestThrottling.Tests.csproj", "{353AA2B0-1013-486C-B5BD-9379385CA403}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Metadata", "..\Http\Metadata\src\Microsoft.AspNetCore.Metadata.csproj", "{7E2EA6E2-31FE-418A-9AE4-955A4C708AE7}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Authorization", "..\Security\Authorization\Core\src\Microsoft.AspNetCore.Authorization.csproj", "{CDDD7C43-5BEB-4E3E-8A59-FCDC83C9FBCF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1571,6 +1575,30 @@ Global {353AA2B0-1013-486C-B5BD-9379385CA403}.Release|x64.Build.0 = Release|Any CPU {353AA2B0-1013-486C-B5BD-9379385CA403}.Release|x86.ActiveCfg = Release|Any CPU {353AA2B0-1013-486C-B5BD-9379385CA403}.Release|x86.Build.0 = Release|Any CPU + {7E2EA6E2-31FE-418A-9AE4-955A4C708AE7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7E2EA6E2-31FE-418A-9AE4-955A4C708AE7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7E2EA6E2-31FE-418A-9AE4-955A4C708AE7}.Debug|x64.ActiveCfg = Debug|Any CPU + {7E2EA6E2-31FE-418A-9AE4-955A4C708AE7}.Debug|x64.Build.0 = Debug|Any CPU + {7E2EA6E2-31FE-418A-9AE4-955A4C708AE7}.Debug|x86.ActiveCfg = Debug|Any CPU + {7E2EA6E2-31FE-418A-9AE4-955A4C708AE7}.Debug|x86.Build.0 = Debug|Any CPU + {7E2EA6E2-31FE-418A-9AE4-955A4C708AE7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7E2EA6E2-31FE-418A-9AE4-955A4C708AE7}.Release|Any CPU.Build.0 = Release|Any CPU + {7E2EA6E2-31FE-418A-9AE4-955A4C708AE7}.Release|x64.ActiveCfg = Release|Any CPU + {7E2EA6E2-31FE-418A-9AE4-955A4C708AE7}.Release|x64.Build.0 = Release|Any CPU + {7E2EA6E2-31FE-418A-9AE4-955A4C708AE7}.Release|x86.ActiveCfg = Release|Any CPU + {7E2EA6E2-31FE-418A-9AE4-955A4C708AE7}.Release|x86.Build.0 = Release|Any CPU + {CDDD7C43-5BEB-4E3E-8A59-FCDC83C9FBCF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CDDD7C43-5BEB-4E3E-8A59-FCDC83C9FBCF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CDDD7C43-5BEB-4E3E-8A59-FCDC83C9FBCF}.Debug|x64.ActiveCfg = Debug|Any CPU + {CDDD7C43-5BEB-4E3E-8A59-FCDC83C9FBCF}.Debug|x64.Build.0 = Debug|Any CPU + {CDDD7C43-5BEB-4E3E-8A59-FCDC83C9FBCF}.Debug|x86.ActiveCfg = Debug|Any CPU + {CDDD7C43-5BEB-4E3E-8A59-FCDC83C9FBCF}.Debug|x86.Build.0 = Debug|Any CPU + {CDDD7C43-5BEB-4E3E-8A59-FCDC83C9FBCF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CDDD7C43-5BEB-4E3E-8A59-FCDC83C9FBCF}.Release|Any CPU.Build.0 = Release|Any CPU + {CDDD7C43-5BEB-4E3E-8A59-FCDC83C9FBCF}.Release|x64.ActiveCfg = Release|Any CPU + {CDDD7C43-5BEB-4E3E-8A59-FCDC83C9FBCF}.Release|x64.Build.0 = Release|Any CPU + {CDDD7C43-5BEB-4E3E-8A59-FCDC83C9FBCF}.Release|x86.ActiveCfg = Release|Any CPU + {CDDD7C43-5BEB-4E3E-8A59-FCDC83C9FBCF}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1695,6 +1723,8 @@ Global {6720919C-0DEA-49E1-90DC-F1883F7919CD} = {8C9AA8A2-9D1F-4450-9F8D-56BAB6F3D343} {4CE2384D-6B88-4824-ADD1-4183D180FEFF} = {8C9AA8A2-9D1F-4450-9F8D-56BAB6F3D343} {353AA2B0-1013-486C-B5BD-9379385CA403} = {8C9AA8A2-9D1F-4450-9F8D-56BAB6F3D343} + {7E2EA6E2-31FE-418A-9AE4-955A4C708AE7} = {ACA6DDB9-7592-47CE-A740-D15BF307E9E0} + {CDDD7C43-5BEB-4E3E-8A59-FCDC83C9FBCF} = {ACA6DDB9-7592-47CE-A740-D15BF307E9E0} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {83786312-A93B-4BB4-AB06-7C6913A59AFA} diff --git a/src/Middleware/StaticFiles/StaticFiles.slnf b/src/Middleware/StaticFiles/StaticFiles.slnf new file mode 100644 index 000000000000..89466b612e07 --- /dev/null +++ b/src/Middleware/StaticFiles/StaticFiles.slnf @@ -0,0 +1,37 @@ +{ + "solution": { + "path": "..\\Middleware.sln", + "projects": [ + "..\\Hosting\\Abstractions\\src\\Microsoft.AspNetCore.Hosting.Abstractions.csproj", + "..\\Hosting\\Hosting\\src\\Microsoft.AspNetCore.Hosting.csproj", + "..\\Hosting\\Server.Abstractions\\src\\Microsoft.AspNetCore.Hosting.Server.Abstractions.csproj", + "..\\Hosting\\Server.IntegrationTesting\\src\\Microsoft.AspNetCore.Server.IntegrationTesting.csproj", + "..\\Hosting\\TestHost\\src\\Microsoft.AspNetCore.TestHost.csproj", + "..\\Http\\Authentication.Abstractions\\src\\Microsoft.AspNetCore.Authentication.Abstractions.csproj", + "..\\Http\\Authentication.Core\\src\\Microsoft.AspNetCore.Authentication.Core.csproj", + "..\\Http\\Http.Abstractions\\src\\Microsoft.AspNetCore.Http.Abstractions.csproj", + "..\\Http\\Http.Extensions\\src\\Microsoft.AspNetCore.Http.Extensions.csproj", + "..\\Http\\Http.Features\\src\\Microsoft.AspNetCore.Http.Features.csproj", + "..\\Http\\Metadata\\src\\Microsoft.AspNetCore.Metadata.csproj", + "..\\Http\\Routing.Abstractions\\src\\Microsoft.AspNetCore.Routing.Abstractions.csproj", + "..\\Http\\WebUtilities\\src\\Microsoft.AspNetCore.WebUtilities.csproj", + "..\\Security\\Authorization\\Core\\src\\Microsoft.AspNetCore.Authorization.csproj", + "..\\Servers\\Connections.Abstractions\\src\\Microsoft.AspNetCore.Connections.Abstractions.csproj", + "..\\Servers\\HttpSys\\src\\Microsoft.AspNetCore.Server.HttpSys.csproj", + "..\\Servers\\IIS\\IISIntegration\\src\\Microsoft.AspNetCore.Server.IISIntegration.csproj", + "..\\Servers\\Kestrel\\Core\\src\\Microsoft.AspNetCore.Server.Kestrel.Core.csproj", + "..\\Servers\\Kestrel\\Kestrel\\src\\Microsoft.AspNetCore.Server.Kestrel.csproj", + "..\\Servers\\Kestrel\\Transport.Abstractions\\src\\Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.csproj", + "..\\Servers\\Kestrel\\Transport.Sockets\\src\\Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.csproj", + "..\\http\\Headers\\src\\Microsoft.Net.Http.Headers.csproj", + "..\\http\\Routing\\src\\Microsoft.AspNetCore.Routing.csproj", + "..\\http\\http\\src\\Microsoft.AspNetCore.Http.csproj", + "HttpOverrides\\src\\Microsoft.AspNetCore.HttpOverrides.csproj", + "ResponseCompression\\src\\Microsoft.AspNetCore.ResponseCompression.csproj", + "StaticFiles\\samples\\StaticFileSample\\StaticFileSample.csproj", + "StaticFiles\\src\\Microsoft.AspNetCore.StaticFiles.csproj", + "StaticFiles\\test\\FunctionalTests\\Microsoft.AspNetCore.StaticFiles.FunctionalTests.csproj", + "StaticFiles\\test\\UnitTests\\Microsoft.AspNetCore.StaticFiles.Tests.csproj" + ] + } +} \ No newline at end of file diff --git a/src/Middleware/StaticFiles/samples/StaticFileSample/Startup.cs b/src/Middleware/StaticFiles/samples/StaticFileSample/Startup.cs index cd504755daf2..b0d553e15d51 100644 --- a/src/Middleware/StaticFiles/samples/StaticFileSample/Startup.cs +++ b/src/Middleware/StaticFiles/samples/StaticFileSample/Startup.cs @@ -17,8 +17,6 @@ public void ConfigureServices(IServiceCollection services) public void Configure(IApplicationBuilder app, IWebHostEnvironment host) { - Console.WriteLine("webroot: " + host.WebRootPath); - app.UseResponseCompression(); app.UseFileServer(new FileServerOptions @@ -37,6 +35,7 @@ public static void Main(string[] args) }) .UseContentRoot(Directory.GetCurrentDirectory()) .UseKestrel() + // .UseHttpSys() .UseIISIntegration() .UseStartup() .Build(); diff --git a/src/Middleware/StaticFiles/samples/StaticFileSample/StaticFileSample.csproj b/src/Middleware/StaticFiles/samples/StaticFileSample/StaticFileSample.csproj index 96301766f247..e9a94e74436a 100644 --- a/src/Middleware/StaticFiles/samples/StaticFileSample/StaticFileSample.csproj +++ b/src/Middleware/StaticFiles/samples/StaticFileSample/StaticFileSample.csproj @@ -1,13 +1,14 @@ - netcoreapp3.0 + OutOfProcess + diff --git a/src/Middleware/StaticFiles/samples/StaticFileSample/wwwroot/SubFolder/index.html b/src/Middleware/StaticFiles/samples/StaticFileSample/wwwroot/SubFolder/index.html new file mode 100644 index 000000000000..707c992658cb --- /dev/null +++ b/src/Middleware/StaticFiles/samples/StaticFileSample/wwwroot/SubFolder/index.html @@ -0,0 +1,11 @@ + + + + + + + + + A static HTML file.
+ + diff --git a/src/Middleware/StaticFiles/src/DefaultFilesMiddleware.cs b/src/Middleware/StaticFiles/src/DefaultFilesMiddleware.cs index b3ce8123d932..3aabe2fe6556 100644 --- a/src/Middleware/StaticFiles/src/DefaultFilesMiddleware.cs +++ b/src/Middleware/StaticFiles/src/DefaultFilesMiddleware.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Extensions; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Options; using Microsoft.Net.Http.Headers; @@ -81,8 +82,10 @@ public Task Invoke(HttpContext context) // This prevents relative links from breaking. if (!Helpers.PathEndsInSlash(context.Request.Path)) { - context.Response.StatusCode = 301; - context.Response.Headers[HeaderNames.Location] = context.Request.PathBase + context.Request.Path + "/" + context.Request.QueryString; + context.Response.StatusCode = StatusCodes.Status301MovedPermanently; + var request = context.Request; + var redirect = UriHelper.BuildAbsolute(request.Scheme, request.Host, request.PathBase, request.Path + "/", request.QueryString); + context.Response.Headers[HeaderNames.Location] = redirect; return Task.CompletedTask; } diff --git a/src/Middleware/StaticFiles/src/DirectoryBrowserMiddleware.cs b/src/Middleware/StaticFiles/src/DirectoryBrowserMiddleware.cs index 4fa79e38ab65..2d0a07b509bd 100644 --- a/src/Middleware/StaticFiles/src/DirectoryBrowserMiddleware.cs +++ b/src/Middleware/StaticFiles/src/DirectoryBrowserMiddleware.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http.Extensions; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Options; using Microsoft.Net.Http.Headers; @@ -88,8 +89,10 @@ public Task Invoke(HttpContext context) // This prevents relative links from breaking. if (!Helpers.PathEndsInSlash(context.Request.Path)) { - context.Response.StatusCode = 301; - context.Response.Headers[HeaderNames.Location] = context.Request.PathBase + context.Request.Path + "/" + context.Request.QueryString; + context.Response.StatusCode = StatusCodes.Status301MovedPermanently; + var request = context.Request; + var redirect = UriHelper.BuildAbsolute(request.Scheme, request.Host, request.PathBase, request.Path + "/", request.QueryString); + context.Response.Headers[HeaderNames.Location] = redirect; return Task.CompletedTask; } diff --git a/src/Middleware/StaticFiles/test/UnitTests/DefaultFilesMiddlewareTests.cs b/src/Middleware/StaticFiles/test/UnitTests/DefaultFilesMiddlewareTests.cs index d88885f1da9e..ed6947593b17 100644 --- a/src/Middleware/StaticFiles/test/UnitTests/DefaultFilesMiddlewareTests.cs +++ b/src/Middleware/StaticFiles/test/UnitTests/DefaultFilesMiddlewareTests.cs @@ -191,9 +191,8 @@ private async Task NearMatch_RedirectAddSlash(string baseUrl, string baseDir, st Assert.Equal(HttpStatusCode.Moved, response.StatusCode); // the url in the header of `Location: /xxx/xxx` should be encoded - var expectedURL = UriHelper.BuildRelative(baseUrl, requestUrl + "/", new QueryString(queryString), new FragmentString()); var actualURL = response.Headers.GetValues("Location").FirstOrDefault(); - Assert.Equal(expectedURL, actualURL); + Assert.Equal("http://localhost" + baseUrl + new PathString(requestUrl + "/") + queryString, actualURL); Assert.Empty((await response.Content.ReadAsByteArrayAsync())); } } diff --git a/src/Middleware/StaticFiles/test/UnitTests/DirectoryBrowserMiddlewareTests.cs b/src/Middleware/StaticFiles/test/UnitTests/DirectoryBrowserMiddlewareTests.cs index 5c966b31366b..c55cb304f5ae 100644 --- a/src/Middleware/StaticFiles/test/UnitTests/DirectoryBrowserMiddlewareTests.cs +++ b/src/Middleware/StaticFiles/test/UnitTests/DirectoryBrowserMiddlewareTests.cs @@ -205,7 +205,7 @@ private async Task NearMatch_RedirectAddSlash(string baseUrl, string baseDir, st var response = await server.CreateRequest(requestUrl + queryString).GetAsync(); Assert.Equal(HttpStatusCode.Moved, response.StatusCode); - Assert.Equal(requestUrl + "/" + queryString, response.Headers.GetValues("Location").FirstOrDefault()); + Assert.Equal("http://localhost" + requestUrl + "/" + queryString, response.Headers.GetValues("Location").FirstOrDefault()); Assert.Empty((await response.Content.ReadAsByteArrayAsync())); } }