Skip to content

Commit 9abf4bf

Browse files
authored
Merge branch 'release/3.1' => 'master' (#16834)
2 parents 911f92c + ea51e63 commit 9abf4bf

File tree

34 files changed

+361
-109
lines changed

34 files changed

+361
-109
lines changed

NuGet.config

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
<configuration>
33
<packageSources>
44
<clear />
5-
<!--Begin: Package sources managed by Dependency Flow automation. Do not edit the sources below.-->
6-
<add key="darc-pub-dotnet-corefx-4ac4c03" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-corefx-4ac4c036/nuget/v3/index.json" />
7-
<!--End: Package sources managed by Dependency Flow automation. Do not edit the sources above.-->
85
<add key="dotnet-core" value="https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json" />
96
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
107
<add key="aspnet-blazor" value="https://dotnetfeed.blob.core.windows.net/aspnet-blazor/index.json" />

src/Components/Blazor/Templates/src/content/BlazorWasm-CSharp/Client/wwwroot/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<div id="blazor-error-ui">
1717
An unhandled error has occurred.
18-
<a href class="reload">Reload</a>
18+
<a href="" class="reload">Reload</a>
1919
<a class="dismiss">🗙</a>
2020
</div>
2121
<script src="_framework/blazor.webassembly.js"></script>

src/Middleware/HttpsPolicy/src/HttpsRedirectionMiddleware.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ private int TryGetHttpsPort()
122122
// 1. Set in the HttpsRedirectionOptions
123123
// 2. HTTPS_PORT environment variable
124124
// 3. IServerAddressesFeature
125-
// 4. Fail if not set
126-
var nullablePort = _config.GetValue<int?>("HTTPS_PORT");
125+
// 4. Fail if not sets
126+
127+
var nullablePort = _config.GetValue<int?>("HTTPS_PORT") ?? _config.GetValue<int?>("ANCM_HTTPS_PORT");
127128
if (nullablePort.HasValue)
128129
{
129130
var port = nullablePort.Value;

src/Mvc/Mvc.Core/src/Infrastructure/ContentResultExecutor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public virtual async Task ExecuteAsync(ActionContext context, ContentResult resu
5555
{
5656
response.ContentLength = resolvedContentTypeEncoding.GetByteCount(result.Content);
5757

58-
using (var textWriter = _httpResponseStreamWriterFactory.CreateWriter(response.Body, resolvedContentTypeEncoding))
58+
await using (var textWriter = _httpResponseStreamWriterFactory.CreateWriter(response.Body, resolvedContentTypeEncoding))
5959
{
6060
await textWriter.WriteAsync(result.Content);
6161

src/Mvc/Mvc.Razor/src/RazorView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ private async Task RenderLayoutAsync(
286286
{
287287
// This means we're writing to a 'real' writer, probably to the actual output stream.
288288
// We're using PagedBufferedTextWriter here to 'smooth' synchronous writes of IHtmlContent values.
289-
using (var writer = _bufferScope.CreateWriter(context.Writer))
289+
await using (var writer = _bufferScope.CreateWriter(context.Writer))
290290
{
291291
await bodyWriter.Buffer.WriteToAsync(writer, _htmlEncoder);
292292
await writer.FlushAsync();

src/Mvc/Mvc.ViewFeatures/src/ViewComponentResultExecutor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public virtual async Task ExecuteAsync(ActionContext context, ViewComponentResul
123123

124124
_writerFactory ??= context.HttpContext.RequestServices.GetRequiredService<IHttpResponseStreamWriterFactory>();
125125

126-
using (var writer = _writerFactory.CreateWriter(response.Body, resolvedContentTypeEncoding))
126+
await using (var writer = _writerFactory.CreateWriter(response.Body, resolvedContentTypeEncoding))
127127
{
128128
var viewContext = new ViewContext(
129129
context,
@@ -149,8 +149,8 @@ public virtual async Task ExecuteAsync(ActionContext context, ViewComponentResul
149149
}
150150
else
151151
{
152-
using var bufferingStream = new FileBufferingWriteStream();
153-
using (var intermediateWriter = _writerFactory.CreateWriter(bufferingStream, resolvedContentTypeEncoding))
152+
await using var bufferingStream = new FileBufferingWriteStream();
153+
await using (var intermediateWriter = _writerFactory.CreateWriter(bufferingStream, resolvedContentTypeEncoding))
154154
{
155155
viewComponentResult.WriteTo(intermediateWriter, _htmlEncoder);
156156
}

src/Mvc/Mvc.ViewFeatures/src/ViewExecutor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ protected async Task ExecuteAsync(
233233

234234
OnExecuting(viewContext);
235235

236-
using (var writer = WriterFactory.CreateWriter(response.Body, resolvedContentTypeEncoding))
236+
await using (var writer = WriterFactory.CreateWriter(response.Body, resolvedContentTypeEncoding))
237237
{
238238
var view = viewContext.View;
239239

src/Mvc/Mvc.ViewFeatures/test/ViewExecutorTest.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,44 @@ public static TheoryData<MediaTypeHeaderValue, string, string> ViewExecutorSetsC
8383
}
8484
}
8585

86+
[Fact]
87+
public async Task ExecuteAsync_ExceptionInSyncContext()
88+
{
89+
// Arrange
90+
var view = CreateView((v) =>
91+
{
92+
v.Writer.Write("xyz");
93+
throw new NotImplementedException("This should be raw!");
94+
});
95+
96+
var context = new DefaultHttpContext();
97+
var stream = new Mock<Stream>();
98+
stream.Setup(s => s.CanWrite).Returns(true);
99+
100+
context.Response.Body = stream.Object;
101+
var actionContext = new ActionContext(
102+
context,
103+
new RouteData(),
104+
new ActionDescriptor());
105+
var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider());
106+
107+
var viewExecutor = CreateViewExecutor();
108+
109+
// Act
110+
var exception = await Assert.ThrowsAsync<NotImplementedException>(async () => await viewExecutor.ExecuteAsync(
111+
actionContext,
112+
view,
113+
viewData,
114+
Mock.Of<ITempDataDictionary>(),
115+
contentType: null,
116+
statusCode: null)
117+
);
118+
119+
// Assert
120+
Assert.Equal("This should be raw!", exception.Message);
121+
stream.Verify(s => s.Write(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>()), Times.Never);
122+
}
123+
86124
[Theory]
87125
[MemberData(nameof(ViewExecutorSetsContentTypeAndEncodingData))]
88126
public async Task ExecuteAsync_SetsContentTypeAndEncoding(

src/Mvc/test/Mvc.FunctionalTests/TagHelpersTest.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ public async Task CanRenderViewsWithTagHelpers(string action)
6464
#endif
6565
}
6666

67+
[Fact]
68+
public async Task GivesCorrectCallstackForSyncronousCalls()
69+
{
70+
// Regression test for https://github.com/aspnet/AspNetCore/issues/15367
71+
// Arrange
72+
var exception = await Assert.ThrowsAsync<HttpRequestException>(async () => await Client.GetAsync("http://localhost/Home/MyHtml"));
73+
74+
// Assert
75+
Assert.Equal("Should be visible", exception.InnerException.InnerException.Message);
76+
}
77+
6778
[Fact]
6879
public async Task CanRenderViewsWithTagHelpersAndUnboundDynamicAttributes_Encoded()
6980
{
@@ -318,4 +329,4 @@ public async Task EncodersPages_ReturnExpectedContent(string actionName)
318329
#endif
319330
}
320331
}
321-
}
332+
}

src/Mvc/test/WebSites/TagHelpersWebSite/Controllers/HomeController.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public IActionResult Help()
3535
return View();
3636
}
3737

38+
public IActionResult MyHtml()
39+
{
40+
return View();
41+
}
42+
3843
public IActionResult ViewComponentTagHelpers()
3944
{
4045
return View();
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.IO;
5+
using System.Text.Encodings.Web;
6+
using Microsoft.AspNetCore.Html;
7+
using Microsoft.AspNetCore.Mvc.Rendering;
8+
9+
namespace TagHelpersWebSite
10+
{
11+
public class MyHtmlContent : IHtmlContent
12+
{
13+
private IHtmlHelper Html { get; }
14+
15+
public MyHtmlContent(IHtmlHelper html)
16+
{
17+
Html = html;
18+
}
19+
20+
public void WriteTo(TextWriter writer, HtmlEncoder encoder)
21+
{
22+
#pragma warning disable MVC1000 // Use of IHtmlHelper.{0} should be avoided.
23+
Html.Partial("_Test").WriteTo(writer, encoder);
24+
#pragma warning restore MVC1000 // Use of IHtmlHelper.{0} should be avoided.
25+
}
26+
}
27+
}

src/Mvc/test/WebSites/TagHelpersWebSite/Startup.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.IO;
55
using Microsoft.AspNetCore.Builder;
6+
using Microsoft.AspNetCore.Diagnostics;
67
using Microsoft.AspNetCore.Hosting;
78
using Microsoft.AspNetCore.Mvc;
89
using Microsoft.Extensions.DependencyInjection;

src/Mvc/test/WebSites/TagHelpersWebSite/TagHelpersWebSite.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<ItemGroup>
1010
<ProjectReference Include="..\RazorPagesClassLibrary\RazorPagesClassLibrary.csproj" />
1111
</ItemGroup>
12-
12+
1313
<ItemGroup>
1414
<Reference Include="Microsoft.AspNetCore.Mvc" />
1515
<Reference Include="Microsoft.AspNetCore.Server.IISIntegration" />
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@(new TagHelpersWebSite.MyHtmlContent(Html))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@{
2+
throw new Exception("Should be visible");
3+
}

src/ProjectTemplates/Web.ProjectTemplates/content/BlazorServerWeb-CSharp/Pages/_Host.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@page "/"
22
@namespace BlazorServerWeb_CSharp.Pages
33
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
4-
@{
4+
@{
55
Layout = null;
66
}
77

@@ -27,7 +27,7 @@
2727
<environment include="Development">
2828
An unhandled exception has occurred. See browser dev tools for details.
2929
</environment>
30-
<a href class="reload">Reload</a>
30+
<a href="" class="reload">Reload</a>
3131
<a class="dismiss">🗙</a>
3232
</div>
3333

src/ProjectTemplates/scripts/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ tmp/
33
CustomHive/
44
angular/
55
blazorserver/
6+
blazorwasm/
67
mvc/
78
razor/
89
react/
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env pwsh
2+
#requires -version 4
3+
4+
# This script packages, installs and creates a template to help with rapid iteration in the templating area.
5+
[CmdletBinding(PositionalBinding = $false)]
6+
param()
7+
8+
Set-StrictMode -Version 2
9+
$ErrorActionPreference = 'Stop'
10+
11+
. $PSScriptRoot\Test-Template.ps1
12+
13+
Test-Template "blazorwasm" "blazorwasm" "Microsoft.AspnetCore.Blazor.Templates.3.1.0-dev.nupkg" $false

src/Servers/IIS/AspNetCoreModuleV2/OutOfProcessRequestHandler/serverprocess.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
#define STARTUP_TIME_LIMIT_INCREMENT_IN_MILLISECONDS 5000
1515

16-
1716
HRESULT
1817
SERVER_PROCESS::Initialize(
1918
PROCESS_MANAGER *pProcessManager,

src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/environmentvariablehash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#define ASPNETCORE_IIS_AUTH_ENV_STR L"ASPNETCORE_IIS_HTTPAUTH"
99
#define ASPNETCORE_IIS_WEBSOCKETS_SUPPORTED_ENV_STR L"ASPNETCORE_IIS_WEBSOCKETS_SUPPORTED"
1010
#define ASPNETCORE_IIS_PHYSICAL_PATH_ENV_STR L"ASPNETCORE_IIS_PHYSICAL_PATH"
11-
#define ASPNETCORE_HTTPS_PORT_ENV_STR L"ASPNETCORE_HTTPS_PORT"
11+
#define ASPNETCORE_ANCM_HTTPS_PORT_ENV_STR L"ASPNETCORE_ANCM_HTTPS_PORT"
1212
#define ASPNETCORE_IIS_AUTH_WINDOWS L"windows;"
1313
#define ASPNETCORE_IIS_AUTH_BASIC L"basic;"
1414
#define ASPNETCORE_IIS_AUTH_ANONYMOUS L"anonymous;"

src/Servers/IIS/AspNetCoreModuleV2/RequestHandlerLib/environmentvariablehelpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ENVIRONMENT_VAR_HELPERS
4343
environmentVariables.insert_or_assign(ASPNETCORE_IIS_PHYSICAL_PATH_ENV_STR, pApplicationPhysicalPath);
4444
if (pHttpsPort)
4545
{
46-
environmentVariables.try_emplace(ASPNETCORE_HTTPS_PORT_ENV_STR, pHttpsPort);
46+
environmentVariables.try_emplace(ASPNETCORE_ANCM_HTTPS_PORT_ENV_STR, pHttpsPort);
4747
}
4848

4949
std::wstring strIisAuthEnvValue;

src/Servers/IIS/IIS/test/Common.FunctionalTests/HttpsTests.cs

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ public async Task HttpsHelloWorld(TestVariant variant)
5757
if (DeployerSelector.HasNewHandler &&
5858
DeployerSelector.HasNewShim)
5959
{
60-
// We expect ServerAddress to be set for InProcess and HTTPS_PORT for OutOfProcess
60+
// We expect ServerAddress to be set for InProcess and ANCM_HTTPS_PORT for OutOfProcess
6161
if (variant.HostingModel == HostingModel.InProcess)
6262
{
6363
Assert.Equal(deploymentParameters.ApplicationBaseUriHint, await client.GetStringAsync("/ServerAddresses"));
6464
}
6565
else
6666
{
67-
Assert.Equal(port.ToString(), await client.GetStringAsync("/HTTPS_PORT"));
67+
Assert.Equal(port.ToString(), await client.GetStringAsync("/ANCM_HTTPS_PORT"));
6868
}
6969
}
7070
}
@@ -113,7 +113,7 @@ public async Task CheckProtocolIsHttp2()
113113
[ConditionalFact]
114114
[RequiresNewHandler]
115115
[RequiresNewShim]
116-
public async Task HttpsPortCanBeOverriden()
116+
public async Task AncmHttpsPortCanBeOverriden()
117117
{
118118
var deploymentParameters = Fixture.GetBaseDeploymentParameters(HostingModel.OutOfProcess);
119119

@@ -125,12 +125,57 @@ public async Task HttpsPortCanBeOverriden()
125125
.SetAttributeValue("bindingInformation", $":{TestPortHelper.GetNextSSLPort()}:localhost");
126126
});
127127

128-
deploymentParameters.WebConfigBasedEnvironmentVariables["ASPNETCORE_HTTPS_PORT"] = "123";
128+
deploymentParameters.WebConfigBasedEnvironmentVariables["ASPNETCORE_ANCM_HTTPS_PORT"] = "123";
129129

130130
var deploymentResult = await DeployAsync(deploymentParameters);
131131
var client = CreateNonValidatingClient(deploymentResult);
132132

133-
Assert.Equal("123", await client.GetStringAsync("/HTTPS_PORT"));
133+
Assert.Equal("123", await client.GetStringAsync("/ANCM_HTTPS_PORT"));
134+
Assert.Equal("NOVALUE", await client.GetStringAsync("/HTTPS_PORT"));
135+
}
136+
137+
[ConditionalFact]
138+
[RequiresNewShim]
139+
public async Task HttpsRedirectionWorksIn30AndNot22()
140+
{
141+
var port = TestPortHelper.GetNextSSLPort();
142+
var deploymentParameters = Fixture.GetBaseDeploymentParameters(HostingModel.OutOfProcess);
143+
deploymentParameters.WebConfigBasedEnvironmentVariables["ENABLE_HTTPS_REDIRECTION"] = "true";
144+
deploymentParameters.ApplicationBaseUriHint = $"http://localhost:{TestPortHelper.GetNextPort()}/";
145+
146+
deploymentParameters.AddServerConfigAction(
147+
element => {
148+
element.Descendants("bindings")
149+
.Single()
150+
.AddAndGetInnerElement("binding", "protocol", "https")
151+
.SetAttributeValue("bindingInformation", $":{port}:localhost");
152+
153+
element.Descendants("access")
154+
.Single()
155+
.SetAttributeValue("sslFlags", "None");
156+
});
157+
158+
var deploymentResult = await DeployAsync(deploymentParameters);
159+
var handler = new HttpClientHandler
160+
{
161+
ServerCertificateCustomValidationCallback = (a, b, c, d) => true,
162+
AllowAutoRedirect = false
163+
};
164+
var client = new HttpClient(handler)
165+
{
166+
BaseAddress = new Uri(deploymentParameters.ApplicationBaseUriHint)
167+
};
168+
169+
if (DeployerSelector.HasNewHandler)
170+
{
171+
var response = await client.GetAsync("/ANCM_HTTPS_PORT");
172+
Assert.Equal(307, (int)response.StatusCode);
173+
}
174+
else
175+
{
176+
var response = await client.GetAsync("/ANCM_HTTPS_PORT");
177+
Assert.Equal(200, (int)response.StatusCode);
178+
}
134179
}
135180

136181
[ConditionalFact]
@@ -159,7 +204,7 @@ public async Task MultipleHttpsPortsProduceNoEnvVar()
159204
var deploymentResult = await DeployAsync(deploymentParameters);
160205
var client = CreateNonValidatingClient(deploymentResult);
161206

162-
Assert.Equal("NOVALUE", await client.GetStringAsync("/HTTPS_PORT"));
207+
Assert.Equal("NOVALUE", await client.GetStringAsync("/ANCM_HTTPS_PORT"));
163208
}
164209

165210
[ConditionalFact]

src/Servers/IIS/IIS/test/testassets/InProcessNewShimWebSite/InProcessNewShimWebSite.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.2.0" >
4343
<AllowExplicitReference>true</AllowExplicitReference>
4444
</PackageReference>
45+
<PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.2.0" >
46+
<AllowExplicitReference>true</AllowExplicitReference>
47+
</PackageReference>
4548
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.2.0" >
4649
<AllowExplicitReference>true</AllowExplicitReference>
4750
</PackageReference>

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/InProcessWebSite.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<Reference Include="Microsoft.AspNetCore.Server.IIS" />
2424
<Reference Include="Microsoft.AspNetCore.Server.IISIntegration" />
2525
<Reference Include="Microsoft.AspNetCore.Server.Kestrel" />
26+
<Reference Include="Microsoft.AspNetCore.HttpsPolicy" />
2627
<Reference Include="Microsoft.AspNetCore.WebUtilities" />
2728
<Reference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" />
2829
<Reference Include="Microsoft.Extensions.Configuration.Json" />

0 commit comments

Comments
 (0)