Static Files cleanup (#10996)
This commit is contained in:
parent
1b5db12d3f
commit
3dc2be22c5
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -17,8 +17,6 @@ namespace StaticFilesSample
|
|||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment host)
|
||||
{
|
||||
Console.WriteLine("webroot: " + host.WebRootPath);
|
||||
|
||||
app.UseResponseCompression();
|
||||
|
||||
app.UseFileServer(new FileServerOptions
|
||||
|
|
@ -37,6 +35,7 @@ namespace StaticFilesSample
|
|||
})
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseKestrel()
|
||||
// .UseHttpSys()
|
||||
.UseIISIntegration()
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.AspNetCore.ResponseCompression" />
|
||||
<Reference Include="Microsoft.AspNetCore.StaticFiles" />
|
||||
<Reference Include="Microsoft.AspNetCore.Server.IISIntegration" />
|
||||
<Reference Include="Microsoft.AspNetCore.Server.HttpSys" />
|
||||
<Reference Include="Microsoft.AspNetCore.Server.Kestrel" />
|
||||
<Reference Include="Microsoft.Extensions.Logging.Console" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
A static HTML file.<br />
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
|||
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 @@ namespace Microsoft.AspNetCore.StaticFiles
|
|||
// 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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
|||
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 @@ namespace Microsoft.AspNetCore.StaticFiles
|
|||
// 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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -191,9 +191,8 @@ namespace Microsoft.AspNetCore.StaticFiles
|
|||
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ namespace Microsoft.AspNetCore.StaticFiles
|
|||
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()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue