修改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 方法的操作默认只接受 GET,供各模块复用。
|
||||
/// 显式 HTTP 方法声明优先;同时补充路由约束和端点元数据,保证接口文档一致。
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = true)]
|
||||
public sealed class DefaultHttpGetAttribute : 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.Get]));
|
||||
selector.EndpointMetadata.Add(new HttpMethodMetadata([HttpMethods.Get]));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user