修改User模块,同步原始代码
This commit is contained in:
1 parent
4a5fada435
commit
78b0c2bb2e
47 files changed
+2939
-193
No files matched your search
@@ -0,0 +1,28 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc.ActionConstraints;
|
||||
using Microsoft.AspNetCore.Mvc.ApplicationModels;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
|
||||
namespace MAX.Framework.Conventions;
|
||||
|
||||
/// <summary>
|
||||
/// 控制器内未声明 HTTP 方法的操作默认只接受 POST。
|
||||
/// 同时补充动作约束和端点元数据,使路由匹配与 OpenAPI 文档保持一致;显式方法声明优先。
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = true)]
|
||||
public sealed class DefaultHttpPostAttribute : Attribute, IControllerModelConvention
|
||||
{
|
||||
public void Apply(ControllerModel controller)
|
||||
{
|
||||
foreach (var action in controller.Actions)
|
||||
foreach (var selector in action.Selectors)
|
||||
{
|
||||
if (selector.ActionConstraints.OfType<HttpMethodActionConstraint>().Any()
|
||||
|| selector.EndpointMetadata.OfType<IHttpMethodMetadata>().Any())
|
||||
continue;
|
||||
|
||||
selector.ActionConstraints.Add(new HttpMethodActionConstraint([HttpMethods.Post]));
|
||||
selector.EndpointMetadata.Add(new HttpMethodMetadata([HttpMethods.Post]));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user