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:
parent
7fad55f6b6
commit
929d7f3306
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
|
|
@ -7,8 +6,6 @@ using Microsoft.AspNetCore.Authorization;
|
|||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Endpoints;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
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.
|
||||
|
|
@ -90,7 +87,7 @@ namespace StaticFilesAuth
|
|||
app.UseStaticFiles();
|
||||
|
||||
app.UseAuthentication();
|
||||
|
||||
|
||||
var files = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "PrivateFiles"));
|
||||
|
||||
app.Map("/MapAuthenticatedFiles", branch =>
|
||||
|
|
|
|||
|
|
@ -270,11 +270,11 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
|
|||
/// Gets a value indicating where the current metadata should be ordered relative to other properties
|
||||
/// in its containing type.
|
||||
/// </summary>
|
||||
/// <value>The order value of the current metadata.</value>
|
||||
/// <remarks>
|
||||
/// <para>For example this property is used to order items in <see cref="Properties"/>.</para>
|
||||
/// <para>The default order is <c>10000</c>.</para>
|
||||
/// </remarks>
|
||||
/// <value>The order value of the current metadata.</value>
|
||||
public abstract int Order { get; }
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -75,40 +75,23 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
|
||||
/// <summary>
|
||||
/// 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>
|
||||
/// 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
|
||||
/// <see cref="ProblemDetails"/> instance (returned as the value for <see cref="ObjectResult"/>).
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// 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>
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The default value is <see langword="true"/> if the version is
|
||||
/// <see cref="CompatibilityVersion.Version_2_2"/> or later; <see langword="false"/> otherwise.
|
||||
/// The default value is <see langword="false"/>.
|
||||
/// </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
|
||||
{
|
||||
// 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>
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The default value is <see langword="true"/> if the version is
|
||||
/// <see cref="CompatibilityVersion.Version_2_2"/> or later; <see langword="false"/> otherwise.
|
||||
/// The default value is <see langword="false"/>.
|
||||
/// </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
|
||||
{
|
||||
get => _suppressUseValidationProblemDetailsForInvalidModelStateResponses.Value;
|
||||
|
|
@ -163,28 +126,8 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
/// </para>
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The default value is <see langword="false"/> if the version is
|
||||
/// <see cref="CompatibilityVersion.Version_2_2"/> or later; <see langword="true"/> otherwise.
|
||||
/// The default value is <see langword="false"/>.
|
||||
/// </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
|
||||
{
|
||||
get => _allowInferringBindingSourceForCollectionTypesAsFromQuery.Value;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// 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;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc
|
||||
|
|
@ -23,7 +24,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
///
|
||||
/// 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
|
||||
/// ASP.NET Core MVC 2.0.
|
||||
/// </summary>
|
||||
[Obsolete("This " + nameof(CompatibilityVersion) + " value is obsolete. The recommended alternatives are " +
|
||||
nameof(Version_3_0) + " or later.")]
|
||||
Version_2_0,
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -49,7 +52,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
/// ASP.NET Core MVC 2.1.
|
||||
/// </summary>
|
||||
/// <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">
|
||||
/// <item><description><see cref="MvcOptions.AllowBindingHeaderValuesToNonStringModelTypes"/></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>
|
||||
/// </list>
|
||||
/// </remarks>
|
||||
[Obsolete("This " + nameof(CompatibilityVersion) + " value is obsolete. The recommended alternatives are " +
|
||||
nameof(Version_3_0) + " or later.")]
|
||||
Version_2_1,
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -67,7 +72,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
/// ASP.NET Core MVC 2.2.
|
||||
/// </summary>
|
||||
/// <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">
|
||||
/// <item><description><c>ApiBehaviorOptions.SuppressMapClientErrors</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>
|
||||
/// </list>
|
||||
/// </remarks>
|
||||
[Obsolete("This " + nameof(CompatibilityVersion) + " value is obsolete. The recommended alternatives are " +
|
||||
nameof(Version_3_0) + " or later.")]
|
||||
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>
|
||||
/// 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"/>.
|
||||
|
|
|
|||
|
|
@ -30,16 +30,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
{
|
||||
get
|
||||
{
|
||||
var dictionary = 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;
|
||||
return new Dictionary<string, object>();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
|||
/// <summary>
|
||||
/// Gets or sets the application's configured <see cref="Mvc.CompatibilityVersion"/>.
|
||||
/// </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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,29 +21,20 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
|||
{
|
||||
get
|
||||
{
|
||||
var values = new Dictionary<string, object>();
|
||||
|
||||
if (Version >= CompatibilityVersion.Version_2_1)
|
||||
return new Dictionary<string, object>
|
||||
{
|
||||
values[nameof(MvcOptions.AllowCombiningAuthorizeFilters)] = true;
|
||||
values[nameof(MvcOptions.AllowBindingHeaderValuesToNonStringModelTypes)] = true;
|
||||
values[nameof(MvcOptions.AllowValidatingTopLevelNodes)] = true;
|
||||
values[nameof(MvcOptions.InputFormatterExceptionPolicy)] = InputFormatterExceptionPolicy.MalformedInputExceptions;
|
||||
values[nameof(MvcOptions.SuppressBindingUndefinedValueToEnumType)] = true;
|
||||
}
|
||||
|
||||
if (Version >= CompatibilityVersion.Version_2_2)
|
||||
{
|
||||
values[nameof(MvcOptions.EnableEndpointRouting)] = true;
|
||||
[nameof(MvcOptions.AllowCombiningAuthorizeFilters)] = true,
|
||||
[nameof(MvcOptions.AllowBindingHeaderValuesToNonStringModelTypes)] = true,
|
||||
[nameof(MvcOptions.AllowValidatingTopLevelNodes)] = true,
|
||||
[nameof(MvcOptions.InputFormatterExceptionPolicy)] = InputFormatterExceptionPolicy.MalformedInputExceptions,
|
||||
[nameof(MvcOptions.SuppressBindingUndefinedValueToEnumType)] = true,
|
||||
[nameof(MvcOptions.EnableEndpointRouting)] = true,
|
||||
|
||||
// Matches JsonSerializerSettingsProvider.DefaultMaxDepth
|
||||
values[nameof(MvcOptions.MaxValidationDepth)] = 32;
|
||||
[nameof(MvcOptions.MaxValidationDepth)] = 32,
|
||||
|
||||
values[nameof(MvcOptions.AllowShortCircuitingValidationWhenNoValidatorsArePresent)] = true;
|
||||
|
||||
}
|
||||
|
||||
return values;
|
||||
[nameof(MvcOptions.AllowShortCircuitingValidationWhenNoValidatorsArePresent)] = true,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,28 +80,8 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
/// URLs with <see cref="IUrlHelper"/>.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The default value is <see langword="true"/> if the version is
|
||||
/// <see cref="CompatibilityVersion.Version_2_2"/> or later; <see langword="false"/> otherwise.
|
||||
/// The default value is <see langword="true"/>.
|
||||
/// </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
|
||||
{
|
||||
get => _enableEndpointRouting.Value;
|
||||
|
|
@ -122,10 +102,12 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
|
||||
/// <summary>
|
||||
/// 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>
|
||||
/// <value>
|
||||
/// The default value is <see langword="true"/>.
|
||||
/// </value>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// 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
|
||||
/// 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
|
||||
/// old (unintended) behavior or the new combining behavior will be used when multiple authorization policies
|
||||
/// 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>
|
||||
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
|
||||
/// <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="Enum"/>, <see cref="bool"/> etc.) or a collection of simple types. The default value of the
|
||||
/// property is <c>false</c>.
|
||||
/// <see cref="Enum"/>, <see cref="bool"/> etc.) or a collection of simple types.
|
||||
/// </summary>
|
||||
/// <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 <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>
|
||||
/// <value>
|
||||
/// The default value is <see langword="true"/>.
|
||||
/// </value>
|
||||
public bool AllowBindingHeaderValuesToNonStringModelTypes
|
||||
{
|
||||
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.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The default value is <see langword="true"/> if the version is
|
||||
/// <see cref="CompatibilityVersion.Version_2_1"/> or later; <see langword="false"/> otherwise.
|
||||
/// The default value is <see langword="true"/>.
|
||||
/// </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
|
||||
{
|
||||
get => _allowValidatingTopLevelNodes.Value;
|
||||
|
|
@ -250,29 +177,10 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
|
||||
/// <summary>
|
||||
/// 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>
|
||||
/// <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 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>
|
||||
/// <value>
|
||||
/// The default value is <see cref="InputFormatterExceptionPolicy.MalformedInputExceptions"/>.
|
||||
/// </value>
|
||||
public InputFormatterExceptionPolicy InputFormatterExceptionPolicy
|
||||
{
|
||||
get => _inputFormatterExceptionPolicy.Value;
|
||||
|
|
@ -286,27 +194,11 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
|
||||
/// <summary>
|
||||
/// 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>
|
||||
/// <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 <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>
|
||||
/// <value>
|
||||
/// The default value is <see langword="true"/>.
|
||||
/// </value>
|
||||
public bool SuppressBindingUndefinedValueToEnumType
|
||||
{
|
||||
get => _suppressBindingUndefinedValueToEnumType.Value;
|
||||
|
|
@ -413,24 +305,10 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
/// When not <see langword="null"/>, <see cref="ValidationVisitor"/> will throw if
|
||||
/// traversing an object exceeds the maximum allowed validation depth.
|
||||
/// </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>
|
||||
/// <value>
|
||||
/// The default value is <c>32</c>.
|
||||
/// </value>
|
||||
public int? MaxValidationDepth
|
||||
{
|
||||
get => _maxValidationDepth.Value;
|
||||
|
|
@ -450,8 +328,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
/// can short-circuit validation when a model does not have any associated validators.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The default value is <see langword="true"/> if the version is
|
||||
/// <see cref="CompatibilityVersion.Version_2_2"/> or later; <see langword="false"/> otherwise.
|
||||
/// The default value is <see langword="true"/>.
|
||||
/// </value>
|
||||
/// <remarks>
|
||||
/// 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
|
||||
/// graph as valid. Setting this property to <see langword="true"/>, allows <see cref="ValidationVisitor"/> to
|
||||
/// 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>
|
||||
public bool AllowShortCircuitingValidationWhenNoValidatorsArePresent
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.DataAnnotations;
|
||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
|
@ -23,14 +22,10 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
{
|
||||
get
|
||||
{
|
||||
var values = new Dictionary<string, object>();
|
||||
|
||||
if (Version >= CompatibilityVersion.Version_2_2)
|
||||
return new Dictionary<string, object>
|
||||
{
|
||||
values[nameof(MvcDataAnnotationsLocalizationOptions.AllowDataAnnotationsLocalizationForEnumDisplayAttributes)] = true;
|
||||
}
|
||||
|
||||
return values;
|
||||
[nameof(MvcDataAnnotationsLocalizationOptions.AllowDataAnnotationsLocalizationForEnumDisplayAttributes)] = true,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,28 +36,13 @@ namespace Microsoft.AspNetCore.Mvc.DataAnnotations
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value that determines if <see cref="MvcDataAnnotationsLocalizationOptions.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.
|
||||
/// 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="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"/>.
|
||||
/// </summary>
|
||||
/// <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"/> 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>
|
||||
/// <value>
|
||||
/// The default value is <see langword="true"/>.
|
||||
/// </value>
|
||||
public bool AllowDataAnnotationsLocalizationForEnumDisplayAttributes
|
||||
{
|
||||
get => _allowDataAnnotationsLocalizationForEnumDisplayAttributes.Value;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
{
|
||||
public MvcJsonOptionsConfigureCompatibilityOptions(
|
||||
ILoggerFactory loggerFactory,
|
||||
IOptions<MvcCompatibilityOptions> compatibilityOptions)
|
||||
IOptions<MvcCompatibilityOptions> compatibilityOptions)
|
||||
: base(loggerFactory, compatibilityOptions)
|
||||
{
|
||||
}
|
||||
|
|
@ -22,14 +22,10 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
{
|
||||
get
|
||||
{
|
||||
var values = new Dictionary<string, object>();
|
||||
|
||||
if (Version >= CompatibilityVersion.Version_2_1)
|
||||
return new Dictionary<string, object>
|
||||
{
|
||||
values[nameof(MvcJsonOptions.AllowInputFormatterExceptionMessages)] = true;
|
||||
}
|
||||
|
||||
return values;
|
||||
[nameof(MvcJsonOptions.AllowInputFormatterExceptionMessages)] = true,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,33 +32,17 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// value is <c>false</c>, meaning that a generic error message will be used instead.
|
||||
/// 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"/>. If
|
||||
/// <see langword="false"/>, a generic error message will be used instead.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The default value is <see langword="true"/>.
|
||||
/// </value>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// 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
|
||||
/// 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>
|
||||
public bool AllowInputFormatterExceptionMessages
|
||||
{
|
||||
|
|
@ -78,4 +62,4 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
|
||||
IEnumerator IEnumerable.GetEnumerator() => _switches.GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Formatters.Xml;
|
||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
|
@ -14,7 +13,7 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
{
|
||||
public MvcXmlOptionsConfigureCompatibilityOptions(
|
||||
ILoggerFactory loggerFactory,
|
||||
IOptions<MvcCompatibilityOptions> compatibilityOptions)
|
||||
IOptions<MvcCompatibilityOptions> compatibilityOptions)
|
||||
: base(loggerFactory, compatibilityOptions)
|
||||
{
|
||||
}
|
||||
|
|
@ -23,14 +22,10 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
{
|
||||
get
|
||||
{
|
||||
var values = new Dictionary<string, object>();
|
||||
|
||||
if (Version >= CompatibilityVersion.Version_2_2)
|
||||
return new Dictionary<string, object>
|
||||
{
|
||||
values[nameof(MvcXmlOptions.AllowRfc7807CompliantProblemDetailsFormat)] = true;
|
||||
}
|
||||
|
||||
return values;
|
||||
[nameof(MvcXmlOptions.AllowRfc7807CompliantProblemDetailsFormat)] = true,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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).
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The default value is <see langword="true"/> if the version is
|
||||
/// <see cref="CompatibilityVersion.Version_2_2"/> or later; <see langword="false"/> otherwise.
|
||||
/// The default value is <see langword="true"/>.
|
||||
/// </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
|
||||
{
|
||||
get => _allowRfc7807CompliantProblemDetailsFormat.Value;
|
||||
|
|
|
|||
|
|
@ -66,30 +66,13 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
|
|||
|
||||
/// <summary>
|
||||
/// Gets or sets a value that determines if areas are enabled for Razor Pages.
|
||||
/// Defaults to <c>false</c>.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The default value is <see langword="true"/>.
|
||||
/// </value>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// 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>.
|
||||
/// </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>
|
||||
public bool AllowAreas
|
||||
{
|
||||
|
|
@ -100,36 +83,21 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
|
|||
/// <summary>
|
||||
/// Gets or sets a value that determines if HTTP method matching for Razor Pages handler methods will use
|
||||
/// fuzzy matching.
|
||||
/// Defaults to <c>false</c>.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The default value is <see langword="true"/>.
|
||||
/// </value>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// When enabled, Razor Pages handler methods will be more flexible in which HTTP methods will be accepted
|
||||
/// by GET and POST handler methods. This allows a GET handler methods to accept the HEAD HTTP methods in
|
||||
/// addition to GET. A more specific handler method can still be defined to accept HEAD, and the most
|
||||
/// by GET and POST handler methods. This allows a GET handler methods to accept the HEAD HTTP methods in
|
||||
/// addition to GET. A more specific handler method can still be defined to accept HEAD, and the most
|
||||
/// specific handler will be invoked.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// 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.
|
||||
/// </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>
|
||||
public bool AllowMappingHeadRequestsToGetHandler
|
||||
{
|
||||
|
|
@ -142,33 +110,13 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
|
|||
/// no handler is available.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The default value is <see langword="true"/> if the version is
|
||||
/// <see cref="CompatibilityVersion.Version_2_2"/> or later; <see langword="false"/> otherwise.
|
||||
/// The default value is <see langword="true"/>.
|
||||
/// </value>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// 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
|
||||
/// 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.
|
||||
/// </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>
|
||||
public bool AllowDefaultHandlingForOptionsRequests
|
||||
{
|
||||
|
|
@ -183,4 +131,4 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
|
|||
|
||||
IEnumerator IEnumerable.GetEnumerator() => _switches.GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
|
|||
{
|
||||
public RazorPagesOptionsConfigureCompatibilityOptions(
|
||||
ILoggerFactory loggerFactory,
|
||||
IOptions<MvcCompatibilityOptions> compatibilityOptions)
|
||||
IOptions<MvcCompatibilityOptions> compatibilityOptions)
|
||||
: base(loggerFactory, compatibilityOptions)
|
||||
{
|
||||
}
|
||||
|
|
@ -21,20 +21,12 @@ namespace Microsoft.AspNetCore.Mvc.RazorPages
|
|||
{
|
||||
get
|
||||
{
|
||||
var values = new Dictionary<string, object>();
|
||||
|
||||
if (Version >= CompatibilityVersion.Version_2_1)
|
||||
return new Dictionary<string, object>
|
||||
{
|
||||
values[nameof(RazorPagesOptions.AllowAreas)] = true;
|
||||
values[nameof(RazorPagesOptions.AllowMappingHeadRequestsToGetHandler)] = true;
|
||||
}
|
||||
|
||||
if (Version >= CompatibilityVersion.Version_2_2)
|
||||
{
|
||||
values[nameof(RazorPagesOptions.AllowDefaultHandlingForOptionsRequests)] = true;
|
||||
}
|
||||
|
||||
return values;
|
||||
[nameof(RazorPagesOptions.AllowAreas)] = true,
|
||||
[nameof(RazorPagesOptions.AllowMappingHeadRequestsToGetHandler)] = true,
|
||||
[nameof(RazorPagesOptions.AllowDefaultHandlingForOptionsRequests)] = true,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
/// the property name e.g. <c>SuccessMessage</c>.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Defaults to <c>false</c>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <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 <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>
|
||||
/// <value>
|
||||
/// The default value is <see langword="true"/>.
|
||||
/// </value>
|
||||
public bool SuppressTempDataAttributePrefix
|
||||
{
|
||||
get => _suppressTempDataAttributePrefix.Value;
|
||||
|
|
@ -96,7 +77,12 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
/// when they're bound to models marked with either
|
||||
/// <see cref="StringLengthAttribute"/> or <see cref="MaxLengthAttribute"/> attributes.
|
||||
/// </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
|
||||
{
|
||||
get => _allowRenderingMaxLengthAttribute.Value;
|
||||
|
|
@ -121,4 +107,4 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
|
||||
IEnumerator IEnumerable.GetEnumerator() => _switches.GetEnumerator();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,19 +21,11 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
|||
{
|
||||
get
|
||||
{
|
||||
var values = new Dictionary<string, object>();
|
||||
|
||||
if (Version >= CompatibilityVersion.Version_2_1)
|
||||
return new Dictionary<string, object>
|
||||
{
|
||||
values[nameof(MvcViewOptions.SuppressTempDataAttributePrefix)] = true;
|
||||
}
|
||||
|
||||
if (Version >= CompatibilityVersion.Version_2_2)
|
||||
{
|
||||
values[nameof(MvcViewOptions.AllowRenderingMaxLengthAttribute)] = true;
|
||||
}
|
||||
|
||||
return values;
|
||||
[nameof(MvcViewOptions.SuppressTempDataAttributePrefix)] = true,
|
||||
[nameof(MvcViewOptions.AllowRenderingMaxLengthAttribute)] = true,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,11 +31,11 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
|||
/// <summary>
|
||||
/// Gets or sets the formatted model value.
|
||||
/// </summary>
|
||||
/// <value>The formatted model value.</value>
|
||||
/// <remarks>
|
||||
/// 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.
|
||||
/// </remarks>
|
||||
/// <value>The formatted model value.</value>
|
||||
public object FormattedModelValue
|
||||
{
|
||||
get { return _formattedModelValue; }
|
||||
|
|
@ -45,10 +45,10 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures
|
|||
/// <summary>
|
||||
/// Gets or sets the HTML field prefix.
|
||||
/// </summary>
|
||||
/// <value>The HTML field prefix.</value>
|
||||
/// <remarks>
|
||||
/// Will never return <c>null</c> for consistency with <see cref="FormattedModelValue"/>.
|
||||
/// </remarks>
|
||||
/// <value>The HTML field prefix.</value>
|
||||
public string HtmlFieldPrefix
|
||||
{
|
||||
get { return _htmlFieldPrefix; }
|
||||
|
|
|
|||
|
|
@ -64,23 +64,6 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
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]
|
||||
public void PostConfigure_DoesNotSetProblemDetailsFactory_IfValueWasModified()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
|||
public void PostConfigure_NoValueForProperty_DoesNothing()
|
||||
{
|
||||
// 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();
|
||||
|
||||
|
|
@ -31,10 +31,12 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
|||
public void PostConfigure_ValueIsSet_DoesNothing()
|
||||
{
|
||||
// Arrange
|
||||
var configure = Create(CompatibilityVersion.Version_2_0, new Dictionary<string, object>()
|
||||
{
|
||||
{ nameof(TestOptions.TestProperty), true },
|
||||
});
|
||||
var configure = Create(
|
||||
CompatibilityVersion.Version_3_0,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ nameof(TestOptions.TestProperty), true },
|
||||
});
|
||||
|
||||
var options = new TestOptions()
|
||||
{
|
||||
|
|
@ -52,10 +54,12 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
|||
public void PostConfigure_ValueNotSet_SetsValue()
|
||||
{
|
||||
// Arrange
|
||||
var configure = Create(CompatibilityVersion.Version_2_0, new Dictionary<string, object>()
|
||||
{
|
||||
{ nameof(TestOptions.TestProperty), true },
|
||||
});
|
||||
var configure = Create(
|
||||
CompatibilityVersion.Version_3_0,
|
||||
new Dictionary<string, object>
|
||||
{
|
||||
{ nameof(TestOptions.TestProperty), true },
|
||||
});
|
||||
|
||||
var options = new TestOptions();
|
||||
|
||||
|
|
@ -67,7 +71,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
|||
}
|
||||
|
||||
private static ConfigureCompatibilityOptions<TestOptions> Create(
|
||||
CompatibilityVersion version,
|
||||
CompatibilityVersion version,
|
||||
IReadOnlyDictionary<string, object> defaultValues)
|
||||
{
|
||||
var compatibilityOptions = Options.Create(new MvcCompatibilityOptions() { CompatibilityVersion = version });
|
||||
|
|
@ -105,7 +109,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
|||
public TestConfigure(
|
||||
ILoggerFactory loggerFactory,
|
||||
IOptions<MvcCompatibilityOptions> compatibilityOptions,
|
||||
IReadOnlyDictionary<string, object> defaultValues)
|
||||
IReadOnlyDictionary<string, object> defaultValues)
|
||||
: base(loggerFactory, compatibilityOptions)
|
||||
{
|
||||
DefaultValues = defaultValues;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Infrastructure
|
|||
var mvcOptions = new MvcOptions();
|
||||
var mvcCompatibilityOptions = new MvcCompatibilityOptions
|
||||
{
|
||||
CompatibilityVersion = CompatibilityVersion.Version_2_2,
|
||||
CompatibilityVersion = CompatibilityVersion.Version_3_0,
|
||||
};
|
||||
|
||||
var configureOptions = new MvcOptionsConfigureCompatibilityOptions(
|
||||
|
|
@ -41,7 +41,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Infrastructure
|
|||
};
|
||||
var mvcCompatibilityOptions = new MvcCompatibilityOptions
|
||||
{
|
||||
CompatibilityVersion = CompatibilityVersion.Version_2_2,
|
||||
CompatibilityVersion = CompatibilityVersion.Version_3_0,
|
||||
};
|
||||
|
||||
var configureOptions = new MvcOptionsConfigureCompatibilityOptions(
|
||||
|
|
@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Infrastructure
|
|||
};
|
||||
var mvcCompatibilityOptions = new MvcCompatibilityOptions
|
||||
{
|
||||
CompatibilityVersion = CompatibilityVersion.Version_2_2,
|
||||
CompatibilityVersion = CompatibilityVersion.Version_3_0,
|
||||
};
|
||||
|
||||
var configureOptions = new MvcOptionsConfigureCompatibilityOptions(
|
||||
|
|
|
|||
|
|
@ -9,5 +9,5 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
|||
: base(fixture)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ using Xunit;
|
|||
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
|
@ -31,4 +31,4 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
|||
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -404,4 +404,4 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
|||
Assert.Empty(content);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,34 +53,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AuthorizationPoliciesDoNotCombine_WithV2_0()
|
||||
{
|
||||
// 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()
|
||||
public async Task AuthorizationPoliciesCombine()
|
||||
{
|
||||
// Arrange & Act 1
|
||||
var response = await Client.PostAsync("http://localhost/Administration/SignInCookie2", null);
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
|||
{
|
||||
// Arrange
|
||||
var client = Factory
|
||||
.WithWebHostBuilder(builder => builder.UseStartup<HtmlGenerationWebSite.StartupWith21CompatibilityBehavior>())
|
||||
.WithWebHostBuilder(builder => builder.UseStartup<HtmlGenerationWebSite.StartupWithoutEndpointRouting>())
|
||||
.CreateDefaultClient();
|
||||
var expectedMediaType = MediaTypeHeaderValue.Parse("text/html; charset=utf-8");
|
||||
var outputFile = "compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Index21Compat.html";
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ using Xunit;
|
|||
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,4 +72,4 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
|||
Assert.Equal("Post", result.Action);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ using Xunit;
|
|||
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
|
@ -30,4 +30,4 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
|||
Assert.False(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -568,4 +568,4 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
|||
public string Link { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ using Xunit;
|
|||
|
||||
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>());
|
||||
Client = Factory.CreateDefaultClient();
|
||||
|
|
@ -260,31 +260,6 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
|||
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]
|
||||
public async Task ValidationProblemDetails_IsSerialized()
|
||||
{
|
||||
|
|
@ -333,33 +308,5 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
|||
var content = await response.Content.ReadAsStringAsync();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ using Xunit;
|
|||
|
||||
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>());
|
||||
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]
|
||||
public async Task ProblemDetails_WithExtensionMembers_IsSerialized()
|
||||
{
|
||||
|
|
@ -308,33 +283,5 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
|||
var content = await response.Content.ReadAsStringAsync();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -191,9 +191,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTests
|
|||
serviceCollection.AddSingleton(Options.Create(mvcOptions));
|
||||
}
|
||||
|
||||
serviceCollection
|
||||
.AddMvc()
|
||||
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
|
||||
serviceCollection.AddMvc();
|
||||
serviceCollection
|
||||
.AddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>()
|
||||
.AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTest
|
|||
public class CompatibilitySwitchIntegrationTest
|
||||
{
|
||||
[Fact]
|
||||
public void CompatibilitySwitches_Version_2_0()
|
||||
public void CompatibilitySwitches_Version_3_0()
|
||||
{
|
||||
// Arrange
|
||||
var serviceCollection = new ServiceCollection();
|
||||
|
|
@ -30,83 +30,7 @@ namespace Microsoft.AspNetCore.Mvc.IntegrationTest
|
|||
serviceCollection
|
||||
.AddMvc()
|
||||
.AddXmlDataContractSerializerFormatters()
|
||||
.SetCompatibilityVersion(CompatibilityVersion.Version_2_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);
|
||||
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
|
||||
|
||||
var services = serviceCollection.BuildServiceProvider();
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ namespace CorsWebSite
|
|||
{
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddMvc()
|
||||
services.AddMvc(ConfigureMvcOptions)
|
||||
.SetCompatibilityVersion(CompatibilityVersion.Latest);
|
||||
services.Configure<CorsOptions>(options =>
|
||||
{
|
||||
|
|
@ -76,5 +76,9 @@ namespace CorsWebSite
|
|||
{
|
||||
app.UseMvc();
|
||||
}
|
||||
|
||||
protected virtual void ConfigureMvcOptions(MvcOptions options)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@ namespace HtmlGenerationWebSite
|
|||
{
|
||||
// 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()
|
||||
services.AddMvc(ConfigureMvcOptions)
|
||||
.InitializeTagHelper<FormTagHelper>((helper, _) => helper.Antiforgery = false)
|
||||
.SetCompatibilityVersion(CompatibilityVersion.Latest);
|
||||
|
||||
|
|
@ -59,5 +59,9 @@ namespace HtmlGenerationWebSite
|
|||
.UseStartup<Startup>()
|
||||
.UseKestrel()
|
||||
.UseIISIntegration();
|
||||
|
||||
protected virtual void ConfigureMvcOptions(MvcOptions options)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -21,13 +21,7 @@ namespace RoutingWebSite
|
|||
var pageRouteTransformerConvention = new PageRouteTransformerConvention(new SlugifyParameterTransformer());
|
||||
|
||||
services
|
||||
.AddMvc(options =>
|
||||
{
|
||||
// Add route token transformer to one controller
|
||||
options.Conventions.Add(new ControllerRouteTokenTransformerConvention(
|
||||
typeof(ParameterTransformerController),
|
||||
new SlugifyParameterTransformer()));
|
||||
})
|
||||
.AddMvc(ConfigureMvcOptions)
|
||||
.AddRazorPagesOptions(options =>
|
||||
{
|
||||
options.Conventions.AddPageRoute("/PageRouteTransformer/PageWithConfiguredRoute", "/PageRouteTransformer/NewConventionRoute/{id?}");
|
||||
|
|
@ -37,11 +31,8 @@ namespace RoutingWebSite
|
|||
});
|
||||
})
|
||||
.SetCompatibilityVersion(CompatibilityVersion.Latest);
|
||||
services
|
||||
.AddRouting(options =>
|
||||
{
|
||||
options.ConstraintMap["slugify"] = typeof(SlugifyParameterTransformer);
|
||||
});
|
||||
|
||||
ConfigureRoutingServices(services);
|
||||
|
||||
services.AddScoped<TestResponseGenerator>();
|
||||
services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();
|
||||
|
|
@ -58,11 +49,7 @@ namespace RoutingWebSite
|
|||
constraints: new { controller = "DataTokens" },
|
||||
dataTokens: new { hasDataTokens = true });
|
||||
|
||||
routes.MapRoute(
|
||||
"ConventionalTransformerRoute",
|
||||
"ConventionalTransformerRoute/{controller:slugify}/{action=Index}/{param:slugify?}",
|
||||
defaults: null,
|
||||
constraints: new { controller = "ConventionalTransformer" });
|
||||
ConfigureConventionalTransformerRoute(routes);
|
||||
|
||||
routes.MapRoute(
|
||||
"DefaultValuesRoute_OptionalParameter",
|
||||
|
|
@ -83,11 +70,7 @@ namespace RoutingWebSite
|
|||
defaults: new { controller = "Home", action = "Index" },
|
||||
constraints: new { area = "Travel" });
|
||||
|
||||
routes.MapRoute(
|
||||
"PageRoute",
|
||||
"{controller}/{action}/{page}",
|
||||
defaults: null,
|
||||
constraints: new { controller = "PageRoute" });
|
||||
ConfigurePageRoute(routes);
|
||||
|
||||
routes.MapRoute(
|
||||
"ActionAsMethod",
|
||||
|
|
@ -104,5 +87,36 @@ namespace RoutingWebSite
|
|||
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" });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -13,7 +13,7 @@ namespace VersioningWebSite
|
|||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
// Add MVC services to the services container
|
||||
services.AddMvc()
|
||||
services.AddMvc(ConfigureMvcOptions)
|
||||
.SetCompatibilityVersion(CompatibilityVersion.Latest);
|
||||
|
||||
services.AddScoped<TestResponseGenerator>();
|
||||
|
|
@ -24,5 +24,9 @@ namespace VersioningWebSite
|
|||
{
|
||||
app.UseMvcWithDefaultRoute();
|
||||
}
|
||||
|
||||
protected virtual void ConfigureMvcOptions(MvcOptions options)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
{
|
||||
"sdk": {
|
||||
"version": "3.0.100-preview-009750"
|
||||
},
|
||||
"msbuild-sdks": {
|
||||
"Internal.AspNetCore.Sdk": "3.0.0-build-20181114.5"
|
||||
}
|
||||
}
|
||||
|
|
@ -125,10 +125,9 @@ namespace Company.WebApplication1
|
|||
.RequireAuthenticatedUser()
|
||||
.Build();
|
||||
options.Filters.Add(new AuthorizeFilter(policy));
|
||||
})
|
||||
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
|
||||
});
|
||||
#else
|
||||
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
|
||||
services.AddMvc();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -124,10 +124,9 @@ namespace Company.WebApplication1
|
|||
.RequireAuthenticatedUser()
|
||||
.Build();
|
||||
options.Filters.Add(new AuthorizeFilter(policy));
|
||||
})
|
||||
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
|
||||
});
|
||||
#else
|
||||
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
|
||||
services.AddMvc();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Company.WebApplication1
|
||||
namespace Company.WebApplication1
|
||||
|
||||
open System
|
||||
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.
|
||||
member this.ConfigureServices(services: IServiceCollection) =
|
||||
// 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.
|
||||
member this.Configure(app: IApplicationBuilder, env: IHostingEnvironment) =
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -43,7 +43,7 @@ namespace Company.WebApplication1
|
|||
services.AddAuthentication(AzureADB2CDefaults.BearerAuthenticationScheme)
|
||||
.AddAzureADB2CBearer(options => Configuration.Bind("AzureAdB2C", options));
|
||||
#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.
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ type Startup private () =
|
|||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
member this.ConfigureServices(services: IServiceCollection) =
|
||||
// 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.
|
||||
member this.Configure(app: IApplicationBuilder, env: IHostingEnvironment) =
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace Company.WebApplication1
|
|||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
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
|
||||
services.AddSpaStaticFiles(configuration =>
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace Company.WebApplication1
|
|||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
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
|
||||
services.AddSpaStaticFiles(configuration =>
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace Company.WebApplication1
|
|||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
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
|
||||
services.AddSpaStaticFiles(configuration =>
|
||||
|
|
|
|||
Loading…
Reference in New Issue