惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog
Y
Y Combinator Blog
N
Netflix TechBlog - Medium
M
MIT News - Artificial intelligence
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
Check Point Blog
The GitHub Blog
The GitHub Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Proofpoint News Feed
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
GbyAI
GbyAI
博客园_首页
A
About on SuperTechFans
Blog — PlanetScale
Blog — PlanetScale
人人都是产品经理
人人都是产品经理
T
Tailwind CSS Blog
aimingoo的专栏
aimingoo的专栏
T
The Blog of Author Tim Ferriss
The Cloudflare Blog

博客园 - HUGO.CM

安装OpenCode后,无法使用。解决方案 vs2022 开发Python 中文报错:SyntaxError: (unicode error) 'utf-8' codec can't decode byte 0xc4 in position 0: invalid continuation byte Abp9.0.4运行DbMigrator,报错“The LINQ expression '@__organizationUnitIds_0' could not be translated. ...” 执行abp命令时,出现死循环解决方案 ABP与BootstrapBlazor 本地化相关处理 【机译】ABP Helper Methods Blazor文件上传异常:Did not receive any data in the allotted time Abp报错:AbpException: No theme registered! Use AbpThemingOptions to register themes. Abp分布式实体缓存 Abp vNext 在控制台输出SQL 【译】在 ABP 框架项目中配置多个数据库上下文 ABP浏览页面报错:Could not find the bundle file '/libs/abp/core/abp.css' for the bundle 'LeptonXLite.Global' 或 'Basic.Global' 运行abp install-libs再报错npm ERR! code E404 Abp配置文件设置IdentityServer客户端 精简版Abp开发教程 - 第三章: 创建应用程序 精简版Abp开发教程 - 第二章: 创建实体与数据库 精简版Abp开发教程 - 第一章: 创建解决方案 Abp vNext 使用Mysql数据库 Abp vNext 修改默认表前缀 Abp vNext 使用sql2005、sql2008等脚本报错解决
修改Abp中Auto API Controllers中 默认生成的 Put、Delete请求
HUGO.CM · 2025-09-23 · via 博客园 - HUGO.CM

在做公家的项目,有个奇葩的规定,Http请求 不能用PutDelete

怎么在使用Abp,自动生成的Api,全局修改原有规则,将修改、删除都改成Post呢?

只需要,在Host项目的XXXModule类中,重写的PreConfigureServices方法,加上如下代码即可。

HttpMethodHelper.ConventionalPrefixes = new Dictionary<string, string[]>
{
    { "GET", ["GetList", "GetAll", "Get"] },
    { "POST", ["Create", "Add", "Insert", "Post", "Put", "Update", "Delete", "Remove", "Patch"] }
};

运行发现,恭喜您报错了

Microsoft.AspNetCore.Routing.Matching.AmbiguousMatchException: The request matched multiple endpoints. Matches: 

Acme.BookStore.Books.BookAppService.DeleteAsync (Acme.BookStore.Application)
Acme.BookStore.Books.BookAppService.UpdateAsync (Acme.BookStore.Application)

解决方案,可重新实现IConventionalRouteBuilder并替换原有实现context.Services.Replace(ServiceDescriptor.Transient<IConventionalRouteBuilder, CustomConventionalRouteBuilder>());

public class CustomConventionalRouteBuilder : ConventionalRouteBuilder
{
    public CustomConventionalRouteBuilder(IOptions<AbpConventionalControllerOptions> options) : base(options)
    {

    }

    public override string Build(
        string rootPath,
        string controllerName,
        ActionModel action,
        string httpMethod,
        ConventionalControllerSetting? configuration)
    {
        var url = base.Build(rootPath, controllerName, action, httpMethod, configuration);
        if (action.ActionName == "Delete" && httpMethod == "POST")
            return $"{url}/Del";
        return url;
    }
}

如果想指定方法,则。只需要项目中添加Microsoft.AspNetCore.Mvc.CoreNuGet包,可以使用ASP.NET Core的标准属性([HttpPost][HttpGet][HttpPut]……)