Obsolete old `CompatibilityVersion` values

- #7156 part 1 of ?
- add `CompatibilityVersion.Version_3_0` and make it the default
- remove tests of old versions
  - also remove `CompatibilityVersion.Version_2_x` uses outside src/Mvc
  - for functional tests of legacy routing, use `MvcOptions.EnableEndpointRouting` to control behaviour
  - rename `StartupWith2xCompat...` classes to `StartupWithoutEndpointRouting`
- clean up comments mentioning `[Obsolete]` `CompatibilityVersion` values
  - many of the affected options will be removed in subsequent PRs but this cleanup helps when searching entire repo
- correct `<value>` comments in `ApiBehaviorOptions`

nits:
- take VS suggestions in changed files
- remove src/SiteExtensions/global.json and let file in repo root "win"
- fix a few grammar errors VS or the spell checker noticed
- move `<value>` elements before `<remarks>` for consistency
  - was undoing unintentional changes and noticed the inconsistency in a couple of additional files
This commit is contained in:
Doug Bunting 2018-11-29 15:07:19 -08:00 committed by Doug Bunting
parent 7fad55f6b6
commit 929d7f3306
58 changed files with 318 additions and 1099 deletions

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.Cookies;
@ -7,8 +6,6 @@ using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Endpoints;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.FileProviders;
@ -71,7 +68,7 @@ namespace StaticFilesAuth
}); });
}); });
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddMvc();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

View File

@ -270,11 +270,11 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
/// Gets a value indicating where the current metadata should be ordered relative to other properties /// Gets a value indicating where the current metadata should be ordered relative to other properties
/// in its containing type. /// in its containing type.
/// </summary> /// </summary>
/// <value>The order value of the current metadata.</value>
/// <remarks> /// <remarks>
/// <para>For example this property is used to order items in <see cref="Properties"/>.</para> /// <para>For example this property is used to order items in <see cref="Properties"/>.</para>
/// <para>The default order is <c>10000</c>.</para> /// <para>The default order is <c>10000</c>.</para>
/// </remarks> /// </remarks>
/// <value>The order value of the current metadata.</value>
public abstract int Order { get; } public abstract int Order { get; }
/// <summary> /// <summary>

View File

@ -75,40 +75,23 @@ namespace Microsoft.AspNetCore.Mvc
/// <summary> /// <summary>
/// Gets or sets a value that determines if controllers with <see cref="ApiControllerAttribute"/> /// Gets or sets a value that determines if controllers with <see cref="ApiControllerAttribute"/>
/// transform certain certain client errors. /// transform certain client errors.
/// <para>
/// When <see langword="false"/>, a result filter is added to API controller actions that transforms
/// <see cref="IClientErrorActionResult"/>. Otherwise, the filter is suppressed.
/// </para>
/// <para> /// <para>
/// When <c>false</c>, a result filter is added to API controller actions that transforms <see cref="IClientErrorActionResult"/>.
/// By default, <see cref="ClientErrorMapping"/> is used to map <see cref="IClientErrorActionResult"/> to a /// By default, <see cref="ClientErrorMapping"/> is used to map <see cref="IClientErrorActionResult"/> to a
/// <see cref="ProblemDetails"/> instance (returned as the value for <see cref="ObjectResult"/>). /// <see cref="ProblemDetails"/> instance (returned as the value for <see cref="ObjectResult"/>).
/// </para> /// </para>
/// <para> /// <para>
/// To customize the output of the filter (for e.g. to return a different error type), register a custom /// To customize the output of the filter (for e.g. to return a different error type), register a custom
/// implementation of of <see cref="IClientErrorFactory"/> in the service collection. /// implementation of <see cref="IClientErrorFactory"/> in the service collection.
/// </para> /// </para>
/// </summary> /// </summary>
/// <value> /// <value>
/// The default value is <see langword="true"/> if the version is /// The default value is <see langword="false"/>.
/// <see cref="CompatibilityVersion.Version_2_2"/> or later; <see langword="false"/> otherwise.
/// </value> /// </value>
/// <remarks>
/// <para>
/// This property is associated with a compatibility switch and can provide a different behavior depending on
/// the configured compatibility version for the application. See <see cref="CompatibilityVersion"/> for
/// guidance and examples of setting the application's compatibility version.
/// </para>
/// <para>
/// Configuring the desired value of the compatibility switch by calling this property's setter will take
/// precedence over the value implied by the application's <see cref="CompatibilityVersion"/>.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_1"/> or
/// lower then this setting will have the value <see langword="false"/> unless explicitly configured.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_2"/> or
/// higher then this setting will have the value <see langword="true"/> unless explicitly configured.
/// </para>
/// </remarks>
public bool SuppressMapClientErrors public bool SuppressMapClientErrors
{ {
// Note: When compatibility switches are removed in 3.0, this property should be retained as a regular boolean property. // Note: When compatibility switches are removed in 3.0, this property should be retained as a regular boolean property.
@ -126,28 +109,8 @@ namespace Microsoft.AspNetCore.Mvc
/// </para> /// </para>
/// </summary> /// </summary>
/// <value> /// <value>
/// The default value is <see langword="true"/> if the version is /// The default value is <see langword="false"/>.
/// <see cref="CompatibilityVersion.Version_2_2"/> or later; <see langword="false"/> otherwise.
/// </value> /// </value>
/// <remarks>
/// <para>
/// This property is associated with a compatibility switch and can provide a different behavior depending on
/// the configured compatibility version for the application. See <see cref="CompatibilityVersion"/> for
/// guidance and examples of setting the application's compatibility version.
/// </para>
/// <para>
/// Configuring the desired value of the compatibility switch by calling this property's setter will take
/// precedence over the value implied by the application's <see cref="CompatibilityVersion"/>.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_1"/> or
/// lower then this setting will have the value <see langword="false"/> unless explicitly configured.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_2"/> or
/// higher then this setting will have the value <see langword="true"/> unless explicitly configured.
/// </para>
/// </remarks>
public bool SuppressUseValidationProblemDetailsForInvalidModelStateResponses public bool SuppressUseValidationProblemDetailsForInvalidModelStateResponses
{ {
get => _suppressUseValidationProblemDetailsForInvalidModelStateResponses.Value; get => _suppressUseValidationProblemDetailsForInvalidModelStateResponses.Value;
@ -163,28 +126,8 @@ namespace Microsoft.AspNetCore.Mvc
/// </para> /// </para>
/// </summary> /// </summary>
/// <value> /// <value>
/// The default value is <see langword="false"/> if the version is /// The default value is <see langword="false"/>.
/// <see cref="CompatibilityVersion.Version_2_2"/> or later; <see langword="true"/> otherwise.
/// </value> /// </value>
/// <remarks>
/// <para>
/// This property is associated with a compatibility switch and can provide a different behavior depending on
/// the configured compatibility version for the application. See <see cref="CompatibilityVersion"/> for
/// guidance and examples of setting the application's compatibility version.
/// </para>
/// <para>
/// Configuring the desired value of the compatibility switch by calling this property's setter takes
/// precedence over the value implied by the application's <see cref="CompatibilityVersion"/>.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_1"/> or
/// lower then this setting will have the value <see langword="true"/> unless explicitly configured.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_2"/> or
/// higher then this setting will have the value <see langword="false"/> unless explicitly configured.
/// </para>
/// </remarks>
public bool AllowInferringBindingSourceForCollectionTypesAsFromQuery public bool AllowInferringBindingSourceForCollectionTypesAsFromQuery
{ {
get => _allowInferringBindingSourceForCollectionTypesAsFromQuery.Value; get => _allowInferringBindingSourceForCollectionTypesAsFromQuery.Value;

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.AspNetCore.Mvc namespace Microsoft.AspNetCore.Mvc
@ -23,7 +24,7 @@ namespace Microsoft.AspNetCore.Mvc
/// ///
/// public void ConfigureServices(IServiceCollection services) /// public void ConfigureServices(IServiceCollection services)
/// { /// {
/// services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); /// services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
/// } /// }
/// ///
/// ... /// ...
@ -42,6 +43,8 @@ namespace Microsoft.AspNetCore.Mvc
/// Sets the default value of settings on <see cref="MvcOptions"/> to match the behavior of /// Sets the default value of settings on <see cref="MvcOptions"/> to match the behavior of
/// ASP.NET Core MVC 2.0. /// ASP.NET Core MVC 2.0.
/// </summary> /// </summary>
[Obsolete("This " + nameof(CompatibilityVersion) + " value is obsolete. The recommended alternatives are " +
nameof(Version_3_0) + " or later.")]
Version_2_0, Version_2_0,
/// <summary> /// <summary>
@ -49,7 +52,7 @@ namespace Microsoft.AspNetCore.Mvc
/// ASP.NET Core MVC 2.1. /// ASP.NET Core MVC 2.1.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// ASP.NET Core MVC 2.1 introduces compatibility switches for the following: /// ASP.NET Core MVC 2.1 introduced compatibility switches for the following:
/// <list type="bullet"> /// <list type="bullet">
/// <item><description><see cref="MvcOptions.AllowBindingHeaderValuesToNonStringModelTypes"/></description></item> /// <item><description><see cref="MvcOptions.AllowBindingHeaderValuesToNonStringModelTypes"/></description></item>
/// <item><description><see cref="MvcOptions.InputFormatterExceptionPolicy"/></description></item> /// <item><description><see cref="MvcOptions.InputFormatterExceptionPolicy"/></description></item>
@ -60,6 +63,8 @@ namespace Microsoft.AspNetCore.Mvc
/// <item><description><c>RazorPagesOptions.AllowMappingHeadRequestsToGetHandler</c></description></item> /// <item><description><c>RazorPagesOptions.AllowMappingHeadRequestsToGetHandler</c></description></item>
/// </list> /// </list>
/// </remarks> /// </remarks>
[Obsolete("This " + nameof(CompatibilityVersion) + " value is obsolete. The recommended alternatives are " +
nameof(Version_3_0) + " or later.")]
Version_2_1, Version_2_1,
/// <summary> /// <summary>
@ -67,7 +72,7 @@ namespace Microsoft.AspNetCore.Mvc
/// ASP.NET Core MVC 2.2. /// ASP.NET Core MVC 2.2.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// ASP.NET Core MVC 2.2 introduces compatibility switches for the following: /// ASP.NET Core MVC 2.2 introduced compatibility switches for the following:
/// <list type="bullet"> /// <list type="bullet">
/// <item><description><c>ApiBehaviorOptions.SuppressMapClientErrors</c></description></item> /// <item><description><c>ApiBehaviorOptions.SuppressMapClientErrors</c></description></item>
/// <item><description><c>ApiBehaviorOptions.SuppressUseValidationProblemDetailsForInvalidModelStateResponses</c></description></item> /// <item><description><c>ApiBehaviorOptions.SuppressUseValidationProblemDetailsForInvalidModelStateResponses</c></description></item>
@ -81,8 +86,16 @@ namespace Microsoft.AspNetCore.Mvc
/// <item><description><c>MvcXmlOptions.AllowRfc7807CompliantProblemDetailsFormat</c></description></item> /// <item><description><c>MvcXmlOptions.AllowRfc7807CompliantProblemDetailsFormat</c></description></item>
/// </list> /// </list>
/// </remarks> /// </remarks>
[Obsolete("This " + nameof(CompatibilityVersion) + " value is obsolete. The recommended alternatives are " +
nameof(Version_3_0) + " or later.")]
Version_2_2, Version_2_2,
/// <summary>
/// Sets the default value of settings on <see cref="MvcOptions"/> and other <c>Options</c> types to match
/// the behavior of ASP.NET Core MVC 3.0.
/// </summary>
Version_3_0,
/// <summary> /// <summary>
/// Sets the default value of settings on <see cref="MvcOptions"/> to match the latest release. Use this /// Sets the default value of settings on <see cref="MvcOptions"/> to match the latest release. Use this
/// value with care, upgrading minor versions will cause breaking changes when using <see cref="Latest"/>. /// value with care, upgrading minor versions will cause breaking changes when using <see cref="Latest"/>.

View File

@ -30,16 +30,7 @@ namespace Microsoft.Extensions.DependencyInjection
{ {
get get
{ {
var dictionary = new Dictionary<string, object>(); return new Dictionary<string, object>();
if (Version < CompatibilityVersion.Version_2_2)
{
dictionary[nameof(ApiBehaviorOptions.SuppressMapClientErrors)] = true;
dictionary[nameof(ApiBehaviorOptions.SuppressUseValidationProblemDetailsForInvalidModelStateResponses)] = true;
dictionary[nameof(ApiBehaviorOptions.AllowInferringBindingSourceForCollectionTypesAsFromQuery)] = true;
}
return dictionary;
} }
} }

View File

@ -18,6 +18,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
/// <summary> /// <summary>
/// Gets or sets the application's configured <see cref="Mvc.CompatibilityVersion"/>. /// Gets or sets the application's configured <see cref="Mvc.CompatibilityVersion"/>.
/// </summary> /// </summary>
public CompatibilityVersion CompatibilityVersion { get; set; } = CompatibilityVersion.Version_2_0; /// <value>the default value is <see cref="CompatibilityVersion.Version_3_0"/>.</value>
public CompatibilityVersion CompatibilityVersion { get; set; } = CompatibilityVersion.Version_3_0;
} }
} }

View File

@ -21,29 +21,20 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
{ {
get get
{ {
var values = new Dictionary<string, object>(); return new Dictionary<string, object>
if (Version >= CompatibilityVersion.Version_2_1)
{ {
values[nameof(MvcOptions.AllowCombiningAuthorizeFilters)] = true; [nameof(MvcOptions.AllowCombiningAuthorizeFilters)] = true,
values[nameof(MvcOptions.AllowBindingHeaderValuesToNonStringModelTypes)] = true; [nameof(MvcOptions.AllowBindingHeaderValuesToNonStringModelTypes)] = true,
values[nameof(MvcOptions.AllowValidatingTopLevelNodes)] = true; [nameof(MvcOptions.AllowValidatingTopLevelNodes)] = true,
values[nameof(MvcOptions.InputFormatterExceptionPolicy)] = InputFormatterExceptionPolicy.MalformedInputExceptions; [nameof(MvcOptions.InputFormatterExceptionPolicy)] = InputFormatterExceptionPolicy.MalformedInputExceptions,
values[nameof(MvcOptions.SuppressBindingUndefinedValueToEnumType)] = true; [nameof(MvcOptions.SuppressBindingUndefinedValueToEnumType)] = true,
} [nameof(MvcOptions.EnableEndpointRouting)] = true,
if (Version >= CompatibilityVersion.Version_2_2)
{
values[nameof(MvcOptions.EnableEndpointRouting)] = true;
// Matches JsonSerializerSettingsProvider.DefaultMaxDepth // Matches JsonSerializerSettingsProvider.DefaultMaxDepth
values[nameof(MvcOptions.MaxValidationDepth)] = 32; [nameof(MvcOptions.MaxValidationDepth)] = 32,
values[nameof(MvcOptions.AllowShortCircuitingValidationWhenNoValidatorsArePresent)] = true; [nameof(MvcOptions.AllowShortCircuitingValidationWhenNoValidatorsArePresent)] = true,
};
}
return values;
} }
} }
} }

View File

@ -80,28 +80,8 @@ namespace Microsoft.AspNetCore.Mvc
/// URLs with <see cref="IUrlHelper"/>. /// URLs with <see cref="IUrlHelper"/>.
/// </summary> /// </summary>
/// <value> /// <value>
/// The default value is <see langword="true"/> if the version is /// The default value is <see langword="true"/>.
/// <see cref="CompatibilityVersion.Version_2_2"/> or later; <see langword="false"/> otherwise.
/// </value> /// </value>
/// <remarks>
/// <para>
/// This property is associated with a compatibility switch and can provide a different behavior depending on
/// the configured compatibility version for the application. See <see cref="CompatibilityVersion"/> for
/// guidance and examples of setting the application's compatibility version.
/// </para>
/// <para>
/// Configuring the desired value of the compatibility switch by calling this property's setter will take
/// precedence over the value implied by the application's <see cref="CompatibilityVersion"/>.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_1"/> or
/// lower then this setting will have the value <see langword="false"/> unless explicitly configured.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_2"/> or
/// higher then this setting will have the value <see langword="true"/> unless explicitly configured.
/// </para>
/// </remarks>
public bool EnableEndpointRouting public bool EnableEndpointRouting
{ {
get => _enableEndpointRouting.Value; get => _enableEndpointRouting.Value;
@ -122,10 +102,12 @@ namespace Microsoft.AspNetCore.Mvc
/// <summary> /// <summary>
/// Gets or sets a value that determines if policies on instances of <see cref="AuthorizeFilter" /> /// Gets or sets a value that determines if policies on instances of <see cref="AuthorizeFilter" />
/// will be combined into a single effective policy. The default value of the property is <c>false</c>. /// will be combined into a single effective policy.
/// </summary> /// </summary>
/// <value>
/// The default value is <see langword="true"/>.
/// </value>
/// <remarks> /// <remarks>
/// <para>
/// Authorization policies are designed such that multiple authorization policies applied to an endpoint /// Authorization policies are designed such that multiple authorization policies applied to an endpoint
/// should be combined and executed a single policy. The <see cref="AuthorizeFilter"/> (commonly applied /// should be combined and executed a single policy. The <see cref="AuthorizeFilter"/> (commonly applied
/// by <see cref="AuthorizeAttribute"/>) can be applied globally, to controllers, and to actions - which /// by <see cref="AuthorizeAttribute"/>) can be applied globally, to controllers, and to actions - which
@ -133,24 +115,6 @@ namespace Microsoft.AspNetCore.Mvc
/// these multiple policies would not combine as intended. This compatibility switch configures whether the /// these multiple policies would not combine as intended. This compatibility switch configures whether the
/// old (unintended) behavior or the new combining behavior will be used when multiple authorization policies /// old (unintended) behavior or the new combining behavior will be used when multiple authorization policies
/// are applied. /// are applied.
/// </para>
/// <para>
/// This property is associated with a compatibility switch and can provide a different behavior depending on
/// the configured compatibility version for the application. See <see cref="CompatibilityVersion"/> for
/// guidance and examples of setting the application's compatibility version.
/// </para>
/// <para>
/// Configuring the desired value of the compatibility switch by calling this property's setter will take precedence
/// over the value implied by the application's <see cref="CompatibilityVersion"/>.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_0"/> then
/// this setting will have the value <c>false</c> unless explicitly configured.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_1"/> or
/// higher then this setting will have the value <c>true</c> unless explicitly configured.
/// </para>
/// </remarks> /// </remarks>
public bool AllowCombiningAuthorizeFilters public bool AllowCombiningAuthorizeFilters
{ {
@ -162,28 +126,11 @@ namespace Microsoft.AspNetCore.Mvc
/// Gets or sets a value that determines if <see cref="HeaderModelBinder"/> should bind to types other than /// Gets or sets a value that determines if <see cref="HeaderModelBinder"/> should bind to types other than
/// <see cref="string"/> or a collection of <see cref="string"/>. If set to <c>true</c>, /// <see cref="string"/> or a collection of <see cref="string"/>. If set to <c>true</c>,
/// <see cref="HeaderModelBinder"/> would bind to simple types (like <see cref="string"/>, <see cref="int"/>, /// <see cref="HeaderModelBinder"/> would bind to simple types (like <see cref="string"/>, <see cref="int"/>,
/// <see cref="Enum"/>, <see cref="bool"/> etc.) or a collection of simple types. The default value of the /// <see cref="Enum"/>, <see cref="bool"/> etc.) or a collection of simple types.
/// property is <c>false</c>.
/// </summary> /// </summary>
/// <remarks> /// <value>
/// <para> /// The default value is <see langword="true"/>.
/// This property is associated with a compatibility switch and can provide a different behavior depending on /// </value>
/// the configured compatibility version for the application. See <see cref="CompatibilityVersion"/> for
/// guidance and examples of setting the application's compatibility version.
/// </para>
/// <para>
/// Configuring the desired value of the compatibility switch by calling this property's setter will take precedence
/// over the value implied by the application's <see cref="CompatibilityVersion"/>.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_0"/> then
/// this setting will have the value <c>false</c> unless explicitly configured.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_1"/> or
/// higher then this setting will have the value <c>true</c> unless explicitly configured.
/// </para>
/// </remarks>
public bool AllowBindingHeaderValuesToNonStringModelTypes public bool AllowBindingHeaderValuesToNonStringModelTypes
{ {
get => _allowBindingHeaderValuesToNonStringModelTypes.Value; get => _allowBindingHeaderValuesToNonStringModelTypes.Value;
@ -197,28 +144,8 @@ namespace Microsoft.AspNetCore.Mvc
/// <c>ValidationAttribute</c>s on these top-level nodes are checked. Otherwise, such attributes are ignored. /// <c>ValidationAttribute</c>s on these top-level nodes are checked. Otherwise, such attributes are ignored.
/// </summary> /// </summary>
/// <value> /// <value>
/// The default value is <see langword="true"/> if the version is /// The default value is <see langword="true"/>.
/// <see cref="CompatibilityVersion.Version_2_1"/> or later; <see langword="false"/> otherwise.
/// </value> /// </value>
/// <remarks>
/// <para>
/// This property is associated with a compatibility switch and can provide a different behavior depending on
/// the configured compatibility version for the application. See <see cref="CompatibilityVersion"/> for
/// guidance and examples of setting the application's compatibility version.
/// </para>
/// <para>
/// Configuring the desired value of the compatibility switch by calling this property's setter will take
/// precedence over the value implied by the application's <see cref="CompatibilityVersion"/>.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_0"/> then
/// this setting will have the value <see langword="false"/> unless explicitly configured.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_1"/> or
/// higher then this setting will have the value <see langword="true"/> unless explicitly configured.
/// </para>
/// </remarks>
public bool AllowValidatingTopLevelNodes public bool AllowValidatingTopLevelNodes
{ {
get => _allowValidatingTopLevelNodes.Value; get => _allowValidatingTopLevelNodes.Value;
@ -250,29 +177,10 @@ namespace Microsoft.AspNetCore.Mvc
/// <summary> /// <summary>
/// Gets or sets a value which determines how the model binding system interprets exceptions thrown by an <see cref="IInputFormatter"/>. /// Gets or sets a value which determines how the model binding system interprets exceptions thrown by an <see cref="IInputFormatter"/>.
/// The default value of the property is <see cref="InputFormatterExceptionPolicy.AllExceptions"/>.
/// </summary> /// </summary>
/// <remarks> /// <value>
/// <para> /// The default value is <see cref="InputFormatterExceptionPolicy.MalformedInputExceptions"/>.
/// This property is associated with a compatibility switch and can provide a different behavior depending on /// </value>
/// the configured compatibility version for the application. See <see cref="CompatibilityVersion"/> for
/// guidance and examples of setting the application's compatibility version.
/// </para>
/// <para>
/// Configuring the desired value of the compatibility switch by calling this property's setter will take precedence
/// over the value implied by the application's <see cref="CompatibilityVersion"/>.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_0"/> then
/// this setting will have the value <see cref="InputFormatterExceptionPolicy.AllExceptions"/> unless
/// explicitly configured.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_1"/> or
/// higher then this setting will have the value
/// <see cref="InputFormatterExceptionPolicy.MalformedInputExceptions"/> unless explicitly configured.
/// </para>
/// </remarks>
public InputFormatterExceptionPolicy InputFormatterExceptionPolicy public InputFormatterExceptionPolicy InputFormatterExceptionPolicy
{ {
get => _inputFormatterExceptionPolicy.Value; get => _inputFormatterExceptionPolicy.Value;
@ -286,27 +194,11 @@ namespace Microsoft.AspNetCore.Mvc
/// <summary> /// <summary>
/// Gets or sets a value indicating whether the model binding system will bind undefined values to /// Gets or sets a value indicating whether the model binding system will bind undefined values to
/// enum types. The default value of the property is <c>false</c>. /// enum types.
/// </summary> /// </summary>
/// <remarks> /// <value>
/// <para> /// The default value is <see langword="true"/>.
/// This property is associated with a compatibility switch and can provide a different behavior depending on /// </value>
/// the configured compatibility version for the application. See <see cref="CompatibilityVersion"/> for
/// guidance and examples of setting the application's compatibility version.
/// </para>
/// <para>
/// Configuring the desired value of the compatibility switch by calling this property's setter will take precedence
/// over the value implied by the application's <see cref="CompatibilityVersion"/>.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_0"/> then
/// this setting will have the value <c>false</c> unless explicitly configured.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_1"/> or
/// higher then this setting will have the value <c>true</c> unless explicitly configured.
/// </para>
/// </remarks>
public bool SuppressBindingUndefinedValueToEnumType public bool SuppressBindingUndefinedValueToEnumType
{ {
get => _suppressBindingUndefinedValueToEnumType.Value; get => _suppressBindingUndefinedValueToEnumType.Value;
@ -413,24 +305,10 @@ namespace Microsoft.AspNetCore.Mvc
/// When not <see langword="null"/>, <see cref="ValidationVisitor"/> will throw if /// When not <see langword="null"/>, <see cref="ValidationVisitor"/> will throw if
/// traversing an object exceeds the maximum allowed validation depth. /// traversing an object exceeds the maximum allowed validation depth.
/// </para> /// </para>
/// <para>
/// This property is associated with a compatibility switch and can provide a different behavior depending on
/// the configured compatibility version for the application. See <see cref="CompatibilityVersion"/> for
/// guidance and examples of setting the application's compatibility version.
/// </para>
/// <para>
/// Configuring the desired value of the compatibility switch by calling this property's setter will take precedence
/// over the value implied by the application's <see cref="CompatibilityVersion"/>.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_2"/> then
/// this setting will have the value <c>200</c> unless explicitly configured.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_1"/> or
/// earlier then this setting will have the value <see langword="null"/> unless explicitly configured.
/// </para>
/// </summary> /// </summary>
/// <value>
/// The default value is <c>32</c>.
/// </value>
public int? MaxValidationDepth public int? MaxValidationDepth
{ {
get => _maxValidationDepth.Value; get => _maxValidationDepth.Value;
@ -450,8 +328,7 @@ namespace Microsoft.AspNetCore.Mvc
/// can short-circuit validation when a model does not have any associated validators. /// can short-circuit validation when a model does not have any associated validators.
/// </summary> /// </summary>
/// <value> /// <value>
/// The default value is <see langword="true"/> if the version is /// The default value is <see langword="true"/>.
/// <see cref="CompatibilityVersion.Version_2_2"/> or later; <see langword="false"/> otherwise.
/// </value> /// </value>
/// <remarks> /// <remarks>
/// When <see cref="ModelMetadata.HasValidators"/> is <see langword="true"/>, that is, it is determined /// When <see cref="ModelMetadata.HasValidators"/> is <see langword="true"/>, that is, it is determined
@ -459,23 +336,6 @@ namespace Microsoft.AspNetCore.Mvc
/// <see cref="ValidationVisitor"/> can short-circuit validation for the model and mark the object /// <see cref="ValidationVisitor"/> can short-circuit validation for the model and mark the object
/// graph as valid. Setting this property to <see langword="true"/>, allows <see cref="ValidationVisitor"/> to /// graph as valid. Setting this property to <see langword="true"/>, allows <see cref="ValidationVisitor"/> to
/// perform this optimization. /// perform this optimization.
/// <para>
/// This property is associated with a compatibility switch and can provide a different behavior depending on
/// the configured compatibility version for the application. See <see cref="CompatibilityVersion"/> for
/// guidance and examples of setting the application's compatibility version.
/// </para>
/// <para>
/// Configuring the desired value of the compatibility switch by calling this property's setter will take precedence
/// over the value implied by the application's <see cref="CompatibilityVersion"/>.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_2"/> then
/// this setting will have the value <see langword="true"/> unless explicitly configured.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_1"/> or
/// earlier then this setting will have the value <see langword="false"/> unless explicitly configured.
/// </para>
/// </remarks> /// </remarks>
public bool AllowShortCircuitingValidationWhenNoValidatorsArePresent public bool AllowShortCircuitingValidationWhenNoValidatorsArePresent
{ {

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.DataAnnotations; using Microsoft.AspNetCore.Mvc.DataAnnotations;
using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -23,14 +22,10 @@ namespace Microsoft.Extensions.DependencyInjection
{ {
get get
{ {
var values = new Dictionary<string, object>(); return new Dictionary<string, object>
if (Version >= CompatibilityVersion.Version_2_2)
{ {
values[nameof(MvcDataAnnotationsLocalizationOptions.AllowDataAnnotationsLocalizationForEnumDisplayAttributes)] = true; [nameof(MvcDataAnnotationsLocalizationOptions.AllowDataAnnotationsLocalizationForEnumDisplayAttributes)] = true,
} };
return values;
} }
} }
} }

View File

@ -36,28 +36,13 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations
} }
/// <summary> /// <summary>
/// Gets or sets a value that determines if <see cref="MvcDataAnnotationsLocalizationOptions.DataAnnotationLocalizerProvider"/> should be used while localizing <see cref="Enum"/> types. /// Gets or sets a value that determines if <see cref="DataAnnotationLocalizerProvider"/> should be used while localizing <see cref="Enum"/> types.
/// If set to <c>true</c> <see cref="MvcDataAnnotationsLocalizationOptions.DataAnnotationLocalizerProvider"/> will be used in localizing <see cref="Enum"/> types. /// If set to <c>true</c> <see cref="DataAnnotationLocalizerProvider"/> will be used in localizing <see cref="Enum"/> types.
/// If set to <c>false</c> the localization will search for values in resource files for the <see cref="Enum"/>. /// If set to <c>false</c> the localization will search for values in resource files for the <see cref="Enum"/>.
/// </summary> /// </summary>
/// <remarks> /// <value>
/// <para> /// The default value is <see langword="true"/>.
/// This property is associated with a compatibility switch and can provide a different behavior depending on /// </value>
/// the configured compatibility version for the application. See <see cref="CompatibilityVersion"/> for guidance and examples of setting the application's compatibility version.
/// </para>
/// <para>
/// Configuring the desired value of the compatibility switch by calling this property's setter will take precedence
/// over the value implied by the application's <see cref="CompatibilityVersion"/>.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_0"/> or <see cref="CompatibilityVersion.Version_2_1"/> then
/// this setting will have the value <c>false</c> unless explicitly configured.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_2"/> or
/// higher then this setting will have the value <c>true</c> unless explicitly configured.
/// </para>
/// </remarks>
public bool AllowDataAnnotationsLocalizationForEnumDisplayAttributes public bool AllowDataAnnotationsLocalizationForEnumDisplayAttributes
{ {
get => _allowDataAnnotationsLocalizationForEnumDisplayAttributes.Value; get => _allowDataAnnotationsLocalizationForEnumDisplayAttributes.Value;

View File

@ -22,14 +22,10 @@ namespace Microsoft.Extensions.DependencyInjection
{ {
get get
{ {
var values = new Dictionary<string, object>(); return new Dictionary<string, object>
if (Version >= CompatibilityVersion.Version_2_1)
{ {
values[nameof(MvcJsonOptions.AllowInputFormatterExceptionMessages)] = true; [nameof(MvcJsonOptions.AllowInputFormatterExceptionMessages)] = true,
} };
return values;
} }
} }
} }

View File

@ -33,32 +33,16 @@ namespace Microsoft.AspNetCore.Mvc
/// <summary> /// <summary>
/// Gets or sets a flag to determine whether error messages from JSON deserialization by the /// Gets or sets a flag to determine whether error messages from JSON deserialization by the
/// <see cref="JsonInputFormatter"/> will be added to the <see cref="ModelStateDictionary"/>. The default /// <see cref="JsonInputFormatter"/> will be added to the <see cref="ModelStateDictionary"/>. If
/// value is <c>false</c>, meaning that a generic error message will be used instead. /// <see langword="false"/>, a generic error message will be used instead.
/// </summary> /// </summary>
/// <value>
/// The default value is <see langword="true"/>.
/// </value>
/// <remarks> /// <remarks>
/// <para>
/// Error messages in the <see cref="ModelStateDictionary"/> are often communicated to clients, either in HTML /// Error messages in the <see cref="ModelStateDictionary"/> are often communicated to clients, either in HTML
/// or using <see cref="BadRequestObjectResult"/>. In effect, this setting controls whether clients can receive /// or using <see cref="BadRequestObjectResult"/>. In effect, this setting controls whether clients can receive
/// detailed error messages about submitted JSON data. /// detailed error messages about submitted JSON data.
/// </para>
/// <para>
/// This property is associated with a compatibility switch and can provide a different behavior depending on
/// the configured compatibility version for the application. See <see cref="CompatibilityVersion"/> for
/// guidance and examples of setting the application's compatibility version.
/// </para>
/// <para>
/// Configuring the desired of the value compatibility switch by calling this property's setter will take precedence
/// over the value implied by the application's <see cref="CompatibilityVersion"/>.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_0"/> then
/// this setting will have value <c>false</c> unless explicitly configured.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_1"/> or
/// higher then this setting will have value <c>true</c> unless explicitly configured.
/// </para>
/// </remarks> /// </remarks>
public bool AllowInputFormatterExceptionMessages public bool AllowInputFormatterExceptionMessages
{ {

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Formatters.Xml; using Microsoft.AspNetCore.Mvc.Formatters.Xml;
using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -23,14 +22,10 @@ namespace Microsoft.Extensions.DependencyInjection
{ {
get get
{ {
var values = new Dictionary<string, object>(); return new Dictionary<string, object>
if (Version >= CompatibilityVersion.Version_2_2)
{ {
values[nameof(MvcXmlOptions.AllowRfc7807CompliantProblemDetailsFormat)] = true; [nameof(MvcXmlOptions.AllowRfc7807CompliantProblemDetailsFormat)] = true,
} };
return values;
} }
} }
} }

View File

@ -33,28 +33,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters.Xml
/// are serialized in a format compliant with the RFC 7807 specification (https://tools.ietf.org/html/rfc7807). /// are serialized in a format compliant with the RFC 7807 specification (https://tools.ietf.org/html/rfc7807).
/// </summary> /// </summary>
/// <value> /// <value>
/// The default value is <see langword="true"/> if the version is /// The default value is <see langword="true"/>.
/// <see cref="CompatibilityVersion.Version_2_2"/> or later; <see langword="false"/> otherwise.
/// </value> /// </value>
/// <remarks>
/// <para>
/// This property is associated with a compatibility switch and can provide a different behavior depending on
/// the configured compatibility version for the application. See <see cref="CompatibilityVersion"/> for
/// guidance and examples of setting the application's compatibility version.
/// </para>
/// <para>
/// Configuring the desired value of the compatibility switch by calling this property's setter will take
/// precedence over the value implied by the application's <see cref="CompatibilityVersion"/>.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_1"/> or
/// lower then this setting will have the value <see langword="false"/> unless explicitly configured.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_2"/> or
/// higher then this setting will have the value <see langword="true"/> unless explicitly configured.
/// </para>
/// </remarks>
public bool AllowRfc7807CompliantProblemDetailsFormat public bool AllowRfc7807CompliantProblemDetailsFormat
{ {
get => _allowRfc7807CompliantProblemDetailsFormat.Value; get => _allowRfc7807CompliantProblemDetailsFormat.Value;

View File

@ -66,30 +66,13 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
/// <summary> /// <summary>
/// Gets or sets a value that determines if areas are enabled for Razor Pages. /// Gets or sets a value that determines if areas are enabled for Razor Pages.
/// Defaults to <c>false</c>.
/// </summary> /// </summary>
/// <value>
/// The default value is <see langword="true"/>.
/// </value>
/// <remarks> /// <remarks>
/// <para>
/// When enabled, any Razor Page under the directory structure <c>/Area/AreaName/Pages/</c> /// When enabled, any Razor Page under the directory structure <c>/Area/AreaName/Pages/</c>
/// will be associated with an area with the name <c>AreaName</c>. /// will be associated with an area with the name <c>AreaName</c>.
/// </para>
/// <para>
/// This property is associated with a compatibility switch and can provide a different behavior depending on
/// the configured compatibility version for the application. See <see cref="CompatibilityVersion"/> for
/// guidance and examples of setting the application's compatibility version.
/// </para>
/// <para>
/// Configuring the desired of the value compatibility switch by calling this property's setter will take precedence
/// over the value implied by the application's <see cref="CompatibilityVersion"/>.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_0"/> then
/// this setting will have value <c>false</c> unless explicitly configured.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_1"/> or
/// higher then this setting will have value <c>true</c> unless explicitly configured.
/// </para>
/// </remarks> /// </remarks>
public bool AllowAreas public bool AllowAreas
{ {
@ -100,8 +83,10 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
/// <summary> /// <summary>
/// Gets or sets a value that determines if HTTP method matching for Razor Pages handler methods will use /// Gets or sets a value that determines if HTTP method matching for Razor Pages handler methods will use
/// fuzzy matching. /// fuzzy matching.
/// Defaults to <c>false</c>.
/// </summary> /// </summary>
/// <value>
/// The default value is <see langword="true"/>.
/// </value>
/// <remarks> /// <remarks>
/// <para> /// <para>
/// When enabled, Razor Pages handler methods will be more flexible in which HTTP methods will be accepted /// When enabled, Razor Pages handler methods will be more flexible in which HTTP methods will be accepted
@ -113,23 +98,6 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
/// This setting reduces the number of handler methods that must be written to correctly respond to typical /// This setting reduces the number of handler methods that must be written to correctly respond to typical
/// web traffic including requests from internet infrastructure such as web crawlers. /// web traffic including requests from internet infrastructure such as web crawlers.
/// </para> /// </para>
/// <para>
/// This property is associated with a compatibility switch and can provide a different behavior depending on
/// the configured compatibility version for the application. See <see cref="CompatibilityVersion"/> for
/// guidance and examples of setting the application's compatibility version.
/// </para>
/// <para>
/// Configuring the desired of the value compatibility switch by calling this property's setter will take precedence
/// over the value implied by the application's <see cref="CompatibilityVersion"/>.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_0"/> then
/// this setting will have value <c>false</c> unless explicitly configured.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_1"/> or
/// higher then this setting will have value <c>true</c> unless explicitly configured.
/// </para>
/// </remarks> /// </remarks>
public bool AllowMappingHeadRequestsToGetHandler public bool AllowMappingHeadRequestsToGetHandler
{ {
@ -142,33 +110,13 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
/// no handler is available. /// no handler is available.
/// </summary> /// </summary>
/// <value> /// <value>
/// The default value is <see langword="true"/> if the version is /// The default value is <see langword="true"/>.
/// <see cref="CompatibilityVersion.Version_2_2"/> or later; <see langword="false"/> otherwise.
/// </value> /// </value>
/// <remarks> /// <remarks>
/// <para>
/// Razor Pages uses the current request's HTTP method to select a handler method. When no handler is available or selected, /// Razor Pages uses the current request's HTTP method to select a handler method. When no handler is available or selected,
/// the page is immediately executed. This may cause runtime errors if the page relies on the handler method to execute /// the page is immediately executed. This may cause runtime errors if the page relies on the handler method to execute
/// and initialize some state. This setting attempts to avoid this class of error for HTTP <c>OPTIONS</c> requests by /// and initialize some state. This setting attempts to avoid this class of error for HTTP <c>OPTIONS</c> requests by
/// returning a <c>200 OK</c> response. /// returning a <c>200 OK</c> response.
/// </para>
/// <para>
/// This property is associated with a compatibility switch and can provide a different behavior depending on
/// the configured compatibility version for the application. See <see cref="CompatibilityVersion"/> for
/// guidance and examples of setting the application's compatibility version.
/// </para>
/// <para>
/// Configuring the desired of the value compatibility switch by calling this property's setter will take precedence
/// over the value implied by the application's <see cref="CompatibilityVersion"/>.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_2"/> then
/// this setting will have value <c>true</c> unless explicitly configured.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_1"/> or
/// lower then this setting will have value <c>true</c> unless explicitly configured.
/// </para>
/// </remarks> /// </remarks>
public bool AllowDefaultHandlingForOptionsRequests public bool AllowDefaultHandlingForOptionsRequests
{ {

View File

@ -21,20 +21,12 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
{ {
get get
{ {
var values = new Dictionary<string, object>(); return new Dictionary<string, object>
if (Version >= CompatibilityVersion.Version_2_1)
{ {
values[nameof(RazorPagesOptions.AllowAreas)] = true; [nameof(RazorPagesOptions.AllowAreas)] = true,
values[nameof(RazorPagesOptions.AllowMappingHeadRequestsToGetHandler)] = true; [nameof(RazorPagesOptions.AllowMappingHeadRequestsToGetHandler)] = true,
} [nameof(RazorPagesOptions.AllowDefaultHandlingForOptionsRequests)] = true,
};
if (Version >= CompatibilityVersion.Version_2_2)
{
values[nameof(RazorPagesOptions.AllowDefaultHandlingForOptionsRequests)] = true;
}
return values;
} }
} }
} }

View File

@ -62,29 +62,10 @@ namespace Microsoft.AspNetCore.Mvc
/// e.g. <c>TempDataProperty-SuccessMessage</c>. When this option is <c>true</c>, the calculated key for the property is /// e.g. <c>TempDataProperty-SuccessMessage</c>. When this option is <c>true</c>, the calculated key for the property is
/// the property name e.g. <c>SuccessMessage</c>. /// the property name e.g. <c>SuccessMessage</c>.
/// </para> /// </para>
/// <para>
/// Defaults to <c>false</c>.
/// </para>
/// </summary> /// </summary>
/// <remarks> /// <value>
/// <para> /// The default value is <see langword="true"/>.
/// This property is associated with a compatibility switch and can provide a different behavior depending on /// </value>
/// the configured compatibility version for the application. See <see cref="CompatibilityVersion"/> for
/// guidance and examples of setting the application's compatibility version.
/// </para>
/// <para>
/// Configuring the desired value of the compatibility switch by calling this property's setter will take precedence
/// over the value implied by the application's <see cref="CompatibilityVersion"/>.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_0"/> then
/// this setting will have the value <c>false</c> unless explicitly configured.
/// </para>
/// <para>
/// If the application's compatibility version is set to <see cref="CompatibilityVersion.Version_2_1"/> or
/// higher then this setting will have the value <c>true</c> unless explicitly configured.
/// </para>
/// </remarks>
public bool SuppressTempDataAttributePrefix public bool SuppressTempDataAttributePrefix
{ {
get => _suppressTempDataAttributePrefix.Value; get => _suppressTempDataAttributePrefix.Value;
@ -96,7 +77,12 @@ namespace Microsoft.AspNetCore.Mvc
/// when they're bound to models marked with either /// when they're bound to models marked with either
/// <see cref="StringLengthAttribute"/> or <see cref="MaxLengthAttribute"/> attributes. /// <see cref="StringLengthAttribute"/> or <see cref="MaxLengthAttribute"/> attributes.
/// </summary> /// </summary>
/// <remarks>If both attributes are specified, the one with the smaller value will be used for the rendered `maxlength` attribute.</remarks> /// <value>
/// The default value is <see langword="true"/>.
/// </value>
/// <remarks>
/// If both attributes are specified, the one with the smaller value will be used for the rendered `maxlength` attribute.
/// </remarks>
public bool AllowRenderingMaxLengthAttribute public bool AllowRenderingMaxLengthAttribute
{ {
get => _allowRenderingMaxLengthAttribute.Value; get => _allowRenderingMaxLengthAttribute.Value;

View File

@ -21,19 +21,11 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
{ {
get get
{ {
var values = new Dictionary<string, object>(); return new Dictionary<string, object>
if (Version >= CompatibilityVersion.Version_2_1)
{ {
values[nameof(MvcViewOptions.SuppressTempDataAttributePrefix)] = true; [nameof(MvcViewOptions.SuppressTempDataAttributePrefix)] = true,
} [nameof(MvcViewOptions.AllowRenderingMaxLengthAttribute)] = true,
};
if (Version >= CompatibilityVersion.Version_2_2)
{
values[nameof(MvcViewOptions.AllowRenderingMaxLengthAttribute)] = true;
}
return values;
} }
} }
} }

View File

@ -31,11 +31,11 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
/// <summary> /// <summary>
/// Gets or sets the formatted model value. /// Gets or sets the formatted model value.
/// </summary> /// </summary>
/// <value>The formatted model value.</value>
/// <remarks> /// <remarks>
/// Will never return <c>null</c> to avoid problems when using HTML helpers within a template. Otherwise the /// Will never return <c>null</c> to avoid problems when using HTML helpers within a template. Otherwise the
/// helpers could find elements in the `ViewDataDictionary`, not the intended Model properties. /// helpers could find elements in the `ViewDataDictionary`, not the intended Model properties.
/// </remarks> /// </remarks>
/// <value>The formatted model value.</value>
public object FormattedModelValue public object FormattedModelValue
{ {
get { return _formattedModelValue; } get { return _formattedModelValue; }
@ -45,10 +45,10 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
/// <summary> /// <summary>
/// Gets or sets the HTML field prefix. /// Gets or sets the HTML field prefix.
/// </summary> /// </summary>
/// <value>The HTML field prefix.</value>
/// <remarks> /// <remarks>
/// Will never return <c>null</c> for consistency with <see cref="FormattedModelValue"/>. /// Will never return <c>null</c> for consistency with <see cref="FormattedModelValue"/>.
/// </remarks> /// </remarks>
/// <value>The HTML field prefix.</value>
public string HtmlFieldPrefix public string HtmlFieldPrefix
{ {
get { return _htmlFieldPrefix; } get { return _htmlFieldPrefix; }

View File

@ -64,23 +64,6 @@ namespace Microsoft.Extensions.DependencyInjection
Assert.Same(ApiBehaviorOptionsSetup.ProblemDetailsFactory, options.InvalidModelStateResponseFactory); Assert.Same(ApiBehaviorOptionsSetup.ProblemDetailsFactory, options.InvalidModelStateResponseFactory);
} }
[Fact]
public void PostConfigure_DoesNotSetProblemDetailsFactoryWithLegacyCompatBehavior()
{
// Arrange
var optionsSetup = new ApiBehaviorOptionsSetup(
NullLoggerFactory.Instance,
Options.Options.Create(new MvcCompatibilityOptions { CompatibilityVersion = CompatibilityVersion.Version_2_1 }));
var options = new ApiBehaviorOptions();
// Act
optionsSetup.Configure(options);
optionsSetup.PostConfigure(string.Empty, options);
// Assert
Assert.Same(ApiBehaviorOptionsSetup.DefaultFactory, options.InvalidModelStateResponseFactory);
}
[Fact] [Fact]
public void PostConfigure_DoesNotSetProblemDetailsFactory_IfValueWasModified() public void PostConfigure_DoesNotSetProblemDetailsFactory_IfValueWasModified()
{ {

View File

@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
public void PostConfigure_NoValueForProperty_DoesNothing() public void PostConfigure_NoValueForProperty_DoesNothing()
{ {
// Arrange // Arrange
var configure = Create(CompatibilityVersion.Version_2_0, new Dictionary<string, object>()); var configure = Create(CompatibilityVersion.Version_3_0, new Dictionary<string, object>());
var options = new TestOptions(); var options = new TestOptions();
@ -31,10 +31,12 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
public void PostConfigure_ValueIsSet_DoesNothing() public void PostConfigure_ValueIsSet_DoesNothing()
{ {
// Arrange // Arrange
var configure = Create(CompatibilityVersion.Version_2_0, new Dictionary<string, object>() var configure = Create(
{ CompatibilityVersion.Version_3_0,
{ nameof(TestOptions.TestProperty), true }, new Dictionary<string, object>
}); {
{ nameof(TestOptions.TestProperty), true },
});
var options = new TestOptions() var options = new TestOptions()
{ {
@ -52,10 +54,12 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
public void PostConfigure_ValueNotSet_SetsValue() public void PostConfigure_ValueNotSet_SetsValue()
{ {
// Arrange // Arrange
var configure = Create(CompatibilityVersion.Version_2_0, new Dictionary<string, object>() var configure = Create(
{ CompatibilityVersion.Version_3_0,
{ nameof(TestOptions.TestProperty), true }, new Dictionary<string, object>
}); {
{ nameof(TestOptions.TestProperty), true },
});
var options = new TestOptions(); var options = new TestOptions();

View File

@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Infrastructure
var mvcOptions = new MvcOptions(); var mvcOptions = new MvcOptions();
var mvcCompatibilityOptions = new MvcCompatibilityOptions var mvcCompatibilityOptions = new MvcCompatibilityOptions
{ {
CompatibilityVersion = CompatibilityVersion.Version_2_2, CompatibilityVersion = CompatibilityVersion.Version_3_0,
}; };
var configureOptions = new MvcOptionsConfigureCompatibilityOptions( var configureOptions = new MvcOptionsConfigureCompatibilityOptions(
@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Infrastructure
}; };
var mvcCompatibilityOptions = new MvcCompatibilityOptions var mvcCompatibilityOptions = new MvcCompatibilityOptions
{ {
CompatibilityVersion = CompatibilityVersion.Version_2_2, CompatibilityVersion = CompatibilityVersion.Version_3_0,
}; };
var configureOptions = new MvcOptionsConfigureCompatibilityOptions( var configureOptions = new MvcOptionsConfigureCompatibilityOptions(
@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Infrastructure
}; };
var mvcCompatibilityOptions = new MvcCompatibilityOptions var mvcCompatibilityOptions = new MvcCompatibilityOptions
{ {
CompatibilityVersion = CompatibilityVersion.Version_2_2, CompatibilityVersion = CompatibilityVersion.Version_3_0,
}; };
var configureOptions = new MvcOptionsConfigureCompatibilityOptions( var configureOptions = new MvcOptionsConfigureCompatibilityOptions(

View File

@ -9,5 +9,5 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
: base(fixture) : base(fixture)
{ {
} }
} }
} }

View File

@ -9,9 +9,9 @@ using Xunit;
namespace Microsoft.AspNetCore.Mvc.FunctionalTests namespace Microsoft.AspNetCore.Mvc.FunctionalTests
{ {
public class CorsTests : CorsTestsBase<CorsWebSite.StartupWith21Compat> public class CorsTests : CorsTestsBase<CorsWebSite.StartupWithoutEndpointRouting>
{ {
public CorsTests(MvcTestFixture<CorsWebSite.StartupWith21Compat> fixture) public CorsTests(MvcTestFixture<CorsWebSite.StartupWithoutEndpointRouting> fixture)
: base(fixture) : base(fixture)
{ {
} }

View File

@ -53,34 +53,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
} }
[Fact] [Fact]
public async Task AuthorizationPoliciesDoNotCombine_WithV2_0() public async Task AuthorizationPoliciesCombine()
{
// Arrange & Act
var client = Factory
.WithWebHostBuilder(builder => builder.UseStartup<SecurityWebSite.StartupWith20CompatAndGlobalDenyAnonymousFilter>())
.CreateDefaultClient();
var response = await client.PostAsync("http://localhost/Administration/SignInCookie2", null);
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.True(response.Headers.Contains("Set-Cookie"));
var cookie2 = response.Headers.GetValues("Set-Cookie").SingleOrDefault();
var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Administration/EitherCookie");
request.Headers.Add("Cookie", cookie2);
// Will fail because default cookie is not sent so [Authorize] fails.
response = await client.SendAsync(request);
Assert.Equal(HttpStatusCode.Redirect, response.StatusCode);
Assert.NotNull(response.Headers.Location);
Assert.Equal(
"http://localhost/Home/Login?ReturnUrl=%2FAdministration%2FEitherCookie",
response.Headers.Location.ToString());
}
[Fact]
public async Task AuthorizationPoliciesCombine_WithV2_1()
{ {
// Arrange & Act 1 // Arrange & Act 1
var response = await Client.PostAsync("http://localhost/Administration/SignInCookie2", null); var response = await Client.PostAsync("http://localhost/Administration/SignInCookie2", null);

View File

@ -143,7 +143,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
{ {
// Arrange // Arrange
var client = Factory var client = Factory
.WithWebHostBuilder(builder => builder.UseStartup<HtmlGenerationWebSite.StartupWith21CompatibilityBehavior>()) .WithWebHostBuilder(builder => builder.UseStartup<HtmlGenerationWebSite.StartupWithoutEndpointRouting>())
.CreateDefaultClient(); .CreateDefaultClient();
var expectedMediaType = MediaTypeHeaderValue.Parse("text/html; charset=utf-8"); var expectedMediaType = MediaTypeHeaderValue.Parse("text/html; charset=utf-8");
var outputFile = "compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Index21Compat.html"; var outputFile = "compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Index21Compat.html";

View File

@ -10,9 +10,9 @@ using Xunit;
namespace Microsoft.AspNetCore.Mvc.FunctionalTests namespace Microsoft.AspNetCore.Mvc.FunctionalTests
{ {
public class RoutingTests : RoutingTestsBase<RoutingWebSite.StartupWith21Compat> public class RoutingTests : RoutingTestsBase<RoutingWebSite.StartupWithoutEndpointRouting>
{ {
public RoutingTests(MvcTestFixture<RoutingWebSite.StartupWith21Compat> fixture) public RoutingTests(MvcTestFixture<RoutingWebSite.StartupWithoutEndpointRouting> fixture)
: base(fixture) : base(fixture)
{ {
} }

View File

@ -8,9 +8,9 @@ using Xunit;
namespace Microsoft.AspNetCore.Mvc.FunctionalTests namespace Microsoft.AspNetCore.Mvc.FunctionalTests
{ {
public class VersioningTests : VersioningTestsBase<VersioningWebSite.StartupWith21Compat> public class VersioningTests : VersioningTestsBase<VersioningWebSite.StartupWithoutEndpointRouting>
{ {
public VersioningTests(MvcTestFixture<VersioningWebSite.StartupWith21Compat> fixture) public VersioningTests(MvcTestFixture<VersioningWebSite.StartupWithoutEndpointRouting> fixture)
: base(fixture) : base(fixture)
{ {
} }

View File

@ -16,9 +16,9 @@ using Xunit;
namespace Microsoft.AspNetCore.Mvc.FunctionalTests namespace Microsoft.AspNetCore.Mvc.FunctionalTests
{ {
public class XmlDataContractSerializerFormattersWrappingTest : IClassFixture<MvcTestFixture<XmlFormattersWebSite.Startup>> public class XmlDataContractSerializerFormattersWrappingTest : IClassFixture<MvcTestFixture<Startup>>
{ {
public XmlDataContractSerializerFormattersWrappingTest(MvcTestFixture<XmlFormattersWebSite.Startup> fixture) public XmlDataContractSerializerFormattersWrappingTest(MvcTestFixture<Startup> fixture)
{ {
Factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(builder => builder.UseStartup<Startup>()); Factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(builder => builder.UseStartup<Startup>());
Client = Factory.CreateDefaultClient(); Client = Factory.CreateDefaultClient();
@ -260,31 +260,6 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
XmlAssert.Equal(expected, content); XmlAssert.Equal(expected, content);
} }
[Fact]
public async Task ProblemDetails_With21Behavior()
{
// Arrange
var expected = "<ProblemDetails>" +
"<Instance>instance</Instance>" +
"<Status>404</Status>" +
"<Title>title</Title>" +
"<Correlation>correlation</Correlation>" +
"<Accounts>Account1 Account2</Accounts>" +
"</ProblemDetails>";
var client = Factory
.WithWebHostBuilder(builder => builder.UseStartup<StartupWith21Compat>())
.CreateDefaultClient();
// Act
var response = await client.GetAsync("/api/XmlDataContractApi/ActionReturningProblemDetails");
// Assert
await response.AssertStatusCodeAsync(HttpStatusCode.NotFound);
var content = await response.Content.ReadAsStringAsync();
XmlAssert.Equal(expected, content);
}
[Fact] [Fact]
public async Task ValidationProblemDetails_IsSerialized() public async Task ValidationProblemDetails_IsSerialized()
{ {
@ -333,33 +308,5 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
var content = await response.Content.ReadAsStringAsync(); var content = await response.Content.ReadAsStringAsync();
XmlAssert.Equal(expected, content); XmlAssert.Equal(expected, content);
} }
[Fact]
public async Task ValidationProblemDetails_With21Behavior()
{
// Arrange
var expected = "<ValidationProblemDetails>" +
"<Detail>some detail</Detail>" +
"<Status>400</Status>" +
"<Title>One or more validation errors occurred.</Title>" +
"<Type>some type</Type>" +
"<CorrelationId>correlation</CorrelationId>" +
"<MVC-Errors>" +
"<Error1>ErrorValue</Error1>" +
"</MVC-Errors>" +
"</ValidationProblemDetails>";
var client = Factory
.WithWebHostBuilder(builder => builder.UseStartup<StartupWith21Compat>())
.CreateDefaultClient();
// Act
var response = await client.GetAsync("/api/XmlDataContractApi/ActionReturningValidationDetailsWithMetadata");
// Assert
await response.AssertStatusCodeAsync(HttpStatusCode.BadRequest);
var content = await response.Content.ReadAsStringAsync();
XmlAssert.Equal(expected, content);
}
} }
} }

View File

@ -15,9 +15,9 @@ using Xunit;
namespace Microsoft.AspNetCore.Mvc.FunctionalTests namespace Microsoft.AspNetCore.Mvc.FunctionalTests
{ {
public class XmlSerializerFormattersWrappingTest : IClassFixture<MvcTestFixture<XmlFormattersWebSite.Startup>> public class XmlSerializerFormattersWrappingTest : IClassFixture<MvcTestFixture<Startup>>
{ {
public XmlSerializerFormattersWrappingTest(MvcTestFixture<XmlFormattersWebSite.Startup> fixture) public XmlSerializerFormattersWrappingTest(MvcTestFixture<Startup> fixture)
{ {
Factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(builder => builder.UseStartup<Startup>()); Factory = fixture.Factories.FirstOrDefault() ?? fixture.WithWebHostBuilder(builder => builder.UseStartup<Startup>());
Client = Factory.CreateDefaultClient(); Client = Factory.CreateDefaultClient();
@ -214,31 +214,6 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
} }
} }
[Fact]
public async Task ProblemDetails_With21Behavior()
{
// Arrange
var expected = "<ProblemDetails>" +
"<Instance>instance</Instance>" +
"<Status>404</Status>" +
"<Title>title</Title>" +
"<Correlation>correlation</Correlation>" +
"<Accounts>Account1 Account2</Accounts>" +
"</ProblemDetails>";
var client = Factory
.WithWebHostBuilder(builder => builder.UseStartup<StartupWith21Compat>())
.CreateDefaultClient();
// Act
var response = await client.GetAsync("/api/XmlSerializerApi/ActionReturningProblemDetails");
// Assert
await response.AssertStatusCodeAsync(HttpStatusCode.NotFound);
var content = await response.Content.ReadAsStringAsync();
XmlAssert.Equal(expected, content);
}
[Fact] [Fact]
public async Task ProblemDetails_WithExtensionMembers_IsSerialized() public async Task ProblemDetails_WithExtensionMembers_IsSerialized()
{ {
@ -308,33 +283,5 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
var content = await response.Content.ReadAsStringAsync(); var content = await response.Content.ReadAsStringAsync();
XmlAssert.Equal(expected, content); XmlAssert.Equal(expected, content);
} }
[Fact]
public async Task ValidationProblemDetails_With21Behavior()
{
// Arrange
var expected = "<ValidationProblemDetails>" +
"<Detail>some detail</Detail>" +
"<Status>400</Status>" +
"<Title>One or more validation errors occurred.</Title>" +
"<Type>some type</Type>" +
"<CorrelationId>correlation</CorrelationId>" +
"<MVC-Errors>" +
"<Error1>ErrorValue</Error1>" +
"</MVC-Errors>" +
"</ValidationProblemDetails>";
var client = Factory
.WithWebHostBuilder(builder => builder.UseStartup<StartupWith21Compat>())
.CreateDefaultClient();
// Act
var response = await client.GetAsync("/api/XmlSerializerApi/ActionReturningValidationDetailsWithMetadata");
// Assert
await response.AssertStatusCodeAsync(HttpStatusCode.BadRequest);
var content = await response.Content.ReadAsStringAsync();
XmlAssert.Equal(expected, content);
}
} }
} }

View File

@ -191,9 +191,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests
serviceCollection.AddSingleton(Options.Create(mvcOptions)); serviceCollection.AddSingleton(Options.Create(mvcOptions));
} }
serviceCollection serviceCollection.AddMvc();
.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
serviceCollection serviceCollection
.AddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>() .AddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>()
.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance) .AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance)

View File

@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTest
public class CompatibilitySwitchIntegrationTest public class CompatibilitySwitchIntegrationTest
{ {
[Fact] [Fact]
public void CompatibilitySwitches_Version_2_0() public void CompatibilitySwitches_Version_3_0()
{ {
// Arrange // Arrange
var serviceCollection = new ServiceCollection(); var serviceCollection = new ServiceCollection();
@ -30,83 +30,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTest
serviceCollection serviceCollection
.AddMvc() .AddMvc()
.AddXmlDataContractSerializerFormatters() .AddXmlDataContractSerializerFormatters()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_0); .SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
var services = serviceCollection.BuildServiceProvider();
// Act
var mvcOptions = services.GetRequiredService<IOptions<MvcOptions>>().Value;
var jsonOptions = services.GetRequiredService<IOptions<MvcJsonOptions>>().Value;
var razorPagesOptions = services.GetRequiredService<IOptions<RazorPagesOptions>>().Value;
var apiBehaviorOptions = services.GetRequiredService<IOptions<ApiBehaviorOptions>>().Value;
var razorViewEngineOptions = services.GetRequiredService<IOptions<RazorViewEngineOptions>>().Value;
var xmlOptions = services.GetRequiredService<IOptions<MvcXmlOptions>>().Value;
// Assert
Assert.False(mvcOptions.AllowCombiningAuthorizeFilters);
Assert.False(mvcOptions.AllowBindingHeaderValuesToNonStringModelTypes);
Assert.False(mvcOptions.SuppressBindingUndefinedValueToEnumType);
Assert.Equal(InputFormatterExceptionPolicy.AllExceptions, mvcOptions.InputFormatterExceptionPolicy);
Assert.False(jsonOptions.AllowInputFormatterExceptionMessages);
Assert.False(razorPagesOptions.AllowAreas);
Assert.False(mvcOptions.EnableEndpointRouting);
Assert.Null(mvcOptions.MaxValidationDepth);
Assert.True(apiBehaviorOptions.SuppressUseValidationProblemDetailsForInvalidModelStateResponses);
Assert.True(apiBehaviorOptions.SuppressMapClientErrors);
Assert.False(razorPagesOptions.AllowDefaultHandlingForOptionsRequests);
Assert.False(xmlOptions.AllowRfc7807CompliantProblemDetailsFormat);
Assert.False(mvcOptions.AllowShortCircuitingValidationWhenNoValidatorsArePresent);
Assert.True(apiBehaviorOptions.AllowInferringBindingSourceForCollectionTypesAsFromQuery);
}
[Fact]
public void CompatibilitySwitches_Version_2_1()
{
// Arrange
var serviceCollection = new ServiceCollection();
AddHostingServices(serviceCollection);
serviceCollection
.AddMvc()
.AddXmlDataContractSerializerFormatters()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
var services = serviceCollection.BuildServiceProvider();
// Act
var mvcOptions = services.GetRequiredService<IOptions<MvcOptions>>().Value;
var jsonOptions = services.GetRequiredService<IOptions<MvcJsonOptions>>().Value;
var razorPagesOptions = services.GetRequiredService<IOptions<RazorPagesOptions>>().Value;
var apiBehaviorOptions = services.GetRequiredService<IOptions<ApiBehaviorOptions>>().Value;
var razorViewEngineOptions = services.GetRequiredService<IOptions<RazorViewEngineOptions>>().Value;
var xmlOptions = services.GetRequiredService<IOptions<MvcXmlOptions>>().Value;
// Assert
Assert.True(mvcOptions.AllowCombiningAuthorizeFilters);
Assert.True(mvcOptions.AllowBindingHeaderValuesToNonStringModelTypes);
Assert.True(mvcOptions.SuppressBindingUndefinedValueToEnumType);
Assert.Equal(InputFormatterExceptionPolicy.MalformedInputExceptions, mvcOptions.InputFormatterExceptionPolicy);
Assert.True(jsonOptions.AllowInputFormatterExceptionMessages);
Assert.True(razorPagesOptions.AllowAreas);
Assert.False(mvcOptions.EnableEndpointRouting);
Assert.Null(mvcOptions.MaxValidationDepth);
Assert.True(apiBehaviorOptions.SuppressUseValidationProblemDetailsForInvalidModelStateResponses);
Assert.True(apiBehaviorOptions.SuppressMapClientErrors);
Assert.False(razorPagesOptions.AllowDefaultHandlingForOptionsRequests);
Assert.False(xmlOptions.AllowRfc7807CompliantProblemDetailsFormat);
Assert.False(mvcOptions.AllowShortCircuitingValidationWhenNoValidatorsArePresent);
Assert.True(apiBehaviorOptions.AllowInferringBindingSourceForCollectionTypesAsFromQuery);
}
[Fact]
public void CompatibilitySwitches_Version_2_2()
{
// Arrange
var serviceCollection = new ServiceCollection();
AddHostingServices(serviceCollection);
serviceCollection
.AddMvc()
.AddXmlDataContractSerializerFormatters()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
var services = serviceCollection.BuildServiceProvider(); var services = serviceCollection.BuildServiceProvider();

View File

@ -12,7 +12,7 @@ namespace CorsWebSite
{ {
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddMvc() services.AddMvc(ConfigureMvcOptions)
.SetCompatibilityVersion(CompatibilityVersion.Latest); .SetCompatibilityVersion(CompatibilityVersion.Latest);
services.Configure<CorsOptions>(options => services.Configure<CorsOptions>(options =>
{ {
@ -76,5 +76,9 @@ namespace CorsWebSite
{ {
app.UseMvc(); app.UseMvc();
} }
protected virtual void ConfigureMvcOptions(MvcOptions options)
{
}
} }
} }

View File

@ -1,80 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Cors.Infrastructure;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
namespace CorsWebSite
{
public class StartupWith21Compat
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.Configure<CorsOptions>(options =>
{
options.AddPolicy(
"AllowAnySimpleRequest",
builder =>
{
builder.AllowAnyOrigin()
.WithMethods("GET", "POST", "HEAD");
});
options.AddPolicy(
"AllowSpecificOrigin",
builder =>
{
builder.WithOrigins("http://example.com");
});
options.AddPolicy(
"WithCredentials",
builder =>
{
builder.AllowCredentials()
.WithOrigins("http://example.com");
});
options.AddPolicy(
"WithCredentialsAnyOrigin",
builder =>
{
builder.AllowCredentials()
.AllowAnyOrigin()
.AllowAnyHeader()
.WithMethods("PUT", "POST")
.WithExposedHeaders("exposed1", "exposed2");
});
options.AddPolicy(
"AllowAll",
builder =>
{
builder.AllowCredentials()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowAnyOrigin();
});
options.AddPolicy(
"Allow example.com",
builder =>
{
builder.AllowCredentials()
.AllowAnyMethod()
.AllowAnyHeader()
.WithOrigins("http://example.com");
});
});
}
public void Configure(IApplicationBuilder app)
{
app.UseMvc();
}
}
}

View File

@ -0,0 +1,15 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Mvc;
namespace CorsWebSite
{
public class StartupWithoutEndpointRouting : Startup
{
protected override void ConfigureMvcOptions(MvcOptions options)
{
options.EnableEndpointRouting = false;
}
}
}

View File

@ -17,7 +17,7 @@ namespace HtmlGenerationWebSite
{ {
// Add MVC services to the services container. Change default FormTagHelper.AntiForgery to false. Usually // Add MVC services to the services container. Change default FormTagHelper.AntiForgery to false. Usually
// null which is interpreted as true unless element includes an action attribute. // null which is interpreted as true unless element includes an action attribute.
services.AddMvc() services.AddMvc(ConfigureMvcOptions)
.InitializeTagHelper<FormTagHelper>((helper, _) => helper.Antiforgery = false) .InitializeTagHelper<FormTagHelper>((helper, _) => helper.Antiforgery = false)
.SetCompatibilityVersion(CompatibilityVersion.Latest); .SetCompatibilityVersion(CompatibilityVersion.Latest);
@ -59,5 +59,9 @@ namespace HtmlGenerationWebSite
.UseStartup<Startup>() .UseStartup<Startup>()
.UseKestrel() .UseKestrel()
.UseIISIntegration(); .UseIISIntegration();
protected virtual void ConfigureMvcOptions(MvcOptions options)
{
}
} }
} }

View File

@ -1,55 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.IO;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.TagHelpers;
using Microsoft.Extensions.DependencyInjection;
namespace HtmlGenerationWebSite
{
public class StartupWith21CompatibilityBehavior
{
// Set up application services
public void ConfigureServices(IServiceCollection services)
{
// Add MVC services to the services container. Change default FormTagHelper.AntiForgery to false. Usually
// null which is interpreted as true unless element includes an action attribute.
services.AddMvc()
.InitializeTagHelper<FormTagHelper>((helper, _) => helper.Antiforgery = false)
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddSingleton(typeof(ISignalTokenProviderService<>), typeof(SignalTokenProviderService<>));
services.AddSingleton<ProductsService>();
}
public void Configure(IApplicationBuilder app)
{
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "areaRoute",
template: "{area:exists}/{controller}/{action}/{id?}",
defaults: new { action = "Index" });
routes.MapRoute(
name: "productRoute",
template: "Product/{action}",
defaults: new { controller = "Product" });
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "HtmlGeneration_Home", action = "Index" });
});
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
new WebHostBuilder()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseKestrel()
.UseIISIntegration();
}
}

View File

@ -0,0 +1,15 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Mvc;
namespace HtmlGenerationWebSite
{
public class StartupWithoutEndpointRouting : Startup
{
protected override void ConfigureMvcOptions(MvcOptions options)
{
options.EnableEndpointRouting = false;
}
}
}

View File

@ -21,13 +21,7 @@ namespace RoutingWebSite
var pageRouteTransformerConvention = new PageRouteTransformerConvention(new SlugifyParameterTransformer()); var pageRouteTransformerConvention = new PageRouteTransformerConvention(new SlugifyParameterTransformer());
services services
.AddMvc(options => .AddMvc(ConfigureMvcOptions)
{
// Add route token transformer to one controller
options.Conventions.Add(new ControllerRouteTokenTransformerConvention(
typeof(ParameterTransformerController),
new SlugifyParameterTransformer()));
})
.AddRazorPagesOptions(options => .AddRazorPagesOptions(options =>
{ {
options.Conventions.AddPageRoute("/PageRouteTransformer/PageWithConfiguredRoute", "/PageRouteTransformer/NewConventionRoute/{id?}"); options.Conventions.AddPageRoute("/PageRouteTransformer/PageWithConfiguredRoute", "/PageRouteTransformer/NewConventionRoute/{id?}");
@ -37,11 +31,8 @@ namespace RoutingWebSite
}); });
}) })
.SetCompatibilityVersion(CompatibilityVersion.Latest); .SetCompatibilityVersion(CompatibilityVersion.Latest);
services
.AddRouting(options => ConfigureRoutingServices(services);
{
options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer);
});
services.AddScoped<TestResponseGenerator>(); services.AddScoped<TestResponseGenerator>();
services.AddSingleton<IActionContextAccessor, ActionContextAccessor>(); services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();
@ -58,11 +49,7 @@ namespace RoutingWebSite
constraints: new { controller = "DataTokens" }, constraints: new { controller = "DataTokens" },
dataTokens: new { hasDataTokens = true }); dataTokens: new { hasDataTokens = true });
routes.MapRoute( ConfigureConventionalTransformerRoute(routes);
"ConventionalTransformerRoute",
"ConventionalTransformerRoute/{controller:slugify}/{action=Index}/{param:slugify?}",
defaults: null,
constraints: new { controller = "ConventionalTransformer" });
routes.MapRoute( routes.MapRoute(
"DefaultValuesRoute_OptionalParameter", "DefaultValuesRoute_OptionalParameter",
@ -83,11 +70,7 @@ namespace RoutingWebSite
defaults: new { controller = "Home", action = "Index" }, defaults: new { controller = "Home", action = "Index" },
constraints: new { area = "Travel" }); constraints: new { area = "Travel" });
routes.MapRoute( ConfigurePageRoute(routes);
"PageRoute",
"{controller}/{action}/{page}",
defaults: null,
constraints: new { controller = "PageRoute" });
routes.MapRoute( routes.MapRoute(
"ActionAsMethod", "ActionAsMethod",
@ -104,5 +87,36 @@ namespace RoutingWebSite
return c.Response.WriteAsync("Hello from middleware after routing"); return c.Response.WriteAsync("Hello from middleware after routing");
})); }));
} }
protected virtual void ConfigureMvcOptions(MvcOptions options)
{
// Add route token transformer to one controller
options.Conventions.Add(new ControllerRouteTokenTransformerConvention(
typeof(ParameterTransformerController),
new SlugifyParameterTransformer()));
}
protected virtual void ConfigureRoutingServices(IServiceCollection services)
{
services.AddRouting(options => options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer));
}
protected virtual void ConfigureConventionalTransformerRoute(IRouteBuilder routes)
{
routes.MapRoute(
"ConventionalTransformerRoute",
"ConventionalTransformerRoute/{controller:slugify}/{action=Index}/{param:slugify?}",
defaults: null,
constraints: new { controller = "ConventionalTransformer" });
}
protected virtual void ConfigurePageRoute(IRouteBuilder routes)
{
routes.MapRoute(
"PageRoute",
"{controller}/{action}/{page}",
defaults: null,
constraints: new { controller = "PageRoute" });
}
} }
} }

View File

@ -1,99 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace RoutingWebSite
{
public class StartupWith21Compat
{
// Set up application services
public void ConfigureServices(IServiceCollection services)
{
var pageRouteTransformerConvention = new PageRouteTransformerConvention(new SlugifyParameterTransformer());
services
.AddMvc()
.AddRazorPagesOptions(options =>
{
options.Conventions.AddPageRoute("/PageRouteTransformer/PageWithConfiguredRoute", "/PageRouteTransformer/NewConventionRoute/{id?}");
options.Conventions.AddFolderRouteModelConvention("/PageRouteTransformer", model =>
{
pageRouteTransformerConvention.Apply(model);
});
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddScoped<TestResponseGenerator>();
services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();
// EndpointRoutingController is not compatible with old routing
// Remove its action to avoid errors
var actionDescriptorProvider = new RemoveControllerActionDescriptorProvider(
new ControllerToRemove
{
ControllerType = typeof(EndpointRoutingController),
Actions = null, // remove all
},
new ControllerToRemove
{
ControllerType = typeof(PageRouteController),
Actions = new[] { nameof(PageRouteController.AttributeRoute) }
});
services.TryAddEnumerable(ServiceDescriptor.Singleton<IActionDescriptorProvider>(actionDescriptorProvider));
}
public void Configure(IApplicationBuilder app)
{
app.UseMvc(routes =>
{
routes.MapRoute(
"DataTokensRoute",
"DataTokensRoute/{controller}/{action}",
defaults: null,
constraints: new { controller = "DataTokens" },
dataTokens: new { hasDataTokens = true });
routes.MapRoute(
"DefaultValuesRoute_OptionalParameter",
"DefaultValuesRoute/Optional/{controller=DEFAULTVALUES}/{action=OPTIONALPARAMETER}/{id?}/{**catchAll}",
defaults: null,
constraints: new { controller = "DefaultValues", action = "OptionalParameter" });
routes.MapRoute(
"DefaultValuesRoute_DefaultParameter",
"DefaultValuesRoute/Default/{controller=DEFAULTVALUES}/{action=DEFAULTPARAMETER}/{id=17}/{**catchAll}",
defaults: null,
constraints: new { controller = "DefaultValues", action = "DefaultParameter" });
routes.MapAreaRoute(
"flightRoute",
"adminRoute",
"{area:exists}/{controller}/{action}",
defaults: new { controller = "Home", action = "Index" },
constraints: new { area = "Travel" });
routes.MapRoute(
"ActionAsMethod",
"{controller}/{action}",
defaults: new { controller = "Home", action = "Index" });
routes.MapRoute(
"RouteWithOptionalSegment",
"{controller}/{action}/{path?}");
});
app.Map("/afterrouting", b => b.Run(c =>
{
return c.Response.WriteAsync("Hello from middleware after routing");
}));
}
}
}

View File

@ -0,0 +1,49 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace RoutingWebSite
{
public class StartupWithoutEndpointRouting : Startup
{
// Do not call base implementations of these methods. Those are specific to endpoint routing.
protected override void ConfigureMvcOptions(MvcOptions options)
{
options.EnableEndpointRouting = false;
}
protected override void ConfigureRoutingServices(IServiceCollection services)
{
// EndpointRoutingController is not compatible with old routing
// Remove its action to avoid errors
var actionDescriptorProvider = new RemoveControllerActionDescriptorProvider(
new ControllerToRemove
{
ControllerType = typeof(EndpointRoutingController),
Actions = null, // remove all
},
new ControllerToRemove
{
ControllerType = typeof(PageRouteController),
Actions = new[] { nameof(PageRouteController.AttributeRoute) }
});
services.TryAddEnumerable(ServiceDescriptor.Singleton<IActionDescriptorProvider>(actionDescriptorProvider));
}
protected override void ConfigureConventionalTransformerRoute(IRouteBuilder routes)
{
// no-op
}
protected override void ConfigurePageRoute(IRouteBuilder routes)
{
// no-op
}
}
}

View File

@ -1,41 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization.Policy;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.Extensions.DependencyInjection;
namespace SecurityWebSite
{
public class StartupWith20CompatAndGlobalDenyAnonymousFilter
{
public void ConfigureServices(IServiceCollection services)
{
services
.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.LoginPath = "/Home/Login";
options.LogoutPath = "/Home/Logout";
}).AddCookie("Cookie2");
services.AddMvc(o =>
{
o.Filters.Add(new AuthorizeFilter());
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_0);
services.AddScoped<IPolicyEvaluator, CountingPolicyEvaluator>();
}
public void Configure(IApplicationBuilder app)
{
app.UseAuthentication();
app.UseMvcWithDefaultRoute();
}
}
}

View File

@ -13,7 +13,7 @@ namespace VersioningWebSite
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
// Add MVC services to the services container // Add MVC services to the services container
services.AddMvc() services.AddMvc(ConfigureMvcOptions)
.SetCompatibilityVersion(CompatibilityVersion.Latest); .SetCompatibilityVersion(CompatibilityVersion.Latest);
services.AddScoped<TestResponseGenerator>(); services.AddScoped<TestResponseGenerator>();
@ -24,5 +24,9 @@ namespace VersioningWebSite
{ {
app.UseMvcWithDefaultRoute(); app.UseMvcWithDefaultRoute();
} }
protected virtual void ConfigureMvcOptions(MvcOptions options)
{
}
} }
} }

View File

@ -1,28 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.DependencyInjection;
namespace VersioningWebSite
{
public class StartupWith21Compat
{
public void ConfigureServices(IServiceCollection services)
{
// Add MVC services to the services container
services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddScoped<TestResponseGenerator>();
services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();
}
public void Configure(IApplicationBuilder app)
{
app.UseMvcWithDefaultRoute();
}
}
}

View File

@ -0,0 +1,15 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Mvc;
namespace VersioningWebSite
{
public class StartupWithoutEndpointRouting : Startup
{
protected override void ConfigureMvcOptions(MvcOptions options)
{
options.EnableEndpointRouting = false;
}
}
}

View File

@ -1,13 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Mvc;
namespace XmlFormattersWebSite
{
public class StartupWith21Compat : Startup
{
public override CompatibilityVersion CompatibilityVersion => CompatibilityVersion.Version_2_1;
}
}

View File

@ -1,8 +0,0 @@
{
"sdk": {
"version": "3.0.100-preview-009750"
},
"msbuild-sdks": {
"Internal.AspNetCore.Sdk": "3.0.0-build-20181114.5"
}
}

View File

@ -125,10 +125,9 @@ namespace Company.WebApplication1
.RequireAuthenticatedUser() .RequireAuthenticatedUser()
.Build(); .Build();
options.Filters.Add(new AuthorizeFilter(policy)); options.Filters.Add(new AuthorizeFilter(policy));
}) });
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
#else #else
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddMvc();
#endif #endif
} }

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -124,10 +124,9 @@ namespace Company.WebApplication1
.RequireAuthenticatedUser() .RequireAuthenticatedUser()
.Build(); .Build();
options.Filters.Add(new AuthorizeFilter(policy)); options.Filters.Add(new AuthorizeFilter(policy));
}) });
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
#else #else
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddMvc();
#endif #endif
} }

View File

@ -1,4 +1,4 @@
namespace Company.WebApplication1 namespace Company.WebApplication1
open System open System
open System.Collections.Generic open System.Collections.Generic
@ -21,7 +21,7 @@ type Startup private () =
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
member this.ConfigureServices(services: IServiceCollection) = member this.ConfigureServices(services: IServiceCollection) =
// Add framework services. // Add framework services.
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2) |> ignore services.AddMvc() |> ignore
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
member this.Configure(app: IApplicationBuilder, env: IHostingEnvironment) = member this.Configure(app: IApplicationBuilder, env: IHostingEnvironment) =

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -43,7 +43,7 @@ namespace Company.WebApplication1
services.AddAuthentication(AzureADB2CDefaults.BearerAuthenticationScheme) services.AddAuthentication(AzureADB2CDefaults.BearerAuthenticationScheme)
.AddAzureADB2CBearer(options => Configuration.Bind("AzureAdB2C", options)); .AddAzureADB2CBearer(options => Configuration.Bind("AzureAdB2C", options));
#endif #endif
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddMvc();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

View File

@ -21,7 +21,7 @@ type Startup private () =
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
member this.ConfigureServices(services: IServiceCollection) = member this.ConfigureServices(services: IServiceCollection) =
// Add framework services. // Add framework services.
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2) |> ignore services.AddMvc() |> ignore
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
member this.Configure(app: IApplicationBuilder, env: IHostingEnvironment) = member this.Configure(app: IApplicationBuilder, env: IHostingEnvironment) =

View File

@ -22,7 +22,7 @@ namespace Company.WebApplication1
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddMvc();
// In production, the Angular files will be served from this directory // In production, the Angular files will be served from this directory
services.AddSpaStaticFiles(configuration => services.AddSpaStaticFiles(configuration =>

View File

@ -22,7 +22,7 @@ namespace Company.WebApplication1
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddMvc();
// In production, the React files will be served from this directory // In production, the React files will be served from this directory
services.AddSpaStaticFiles(configuration => services.AddSpaStaticFiles(configuration =>

View File

@ -22,7 +22,7 @@ namespace Company.WebApplication1
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddMvc();
// In production, the React files will be served from this directory // In production, the React files will be served from this directory
services.AddSpaStaticFiles(configuration => services.AddSpaStaticFiles(configuration =>