路由前缀全局统一配置只有在动态控制器没有 [route("xx")]
和方法上没有 [route]
与 [HttpGet/HttpPost]
标记时才生效。
"DynamicApiControllerSettings": {
"DefaultRoutePrefix": "mp"
}
api路径:
"DynamicApiControllerSettings": {
"DefaultRoutePrefix": "mp"
}
/// <summary>
/// 系统服务接口
/// </summary>
//[Route("sys")]
public class SystemAppService : IDynamicApiController
{
private readonly ISystemService _systemService;
public SystemAppService(ISystemService systemService)
{
_systemService = systemService;
}
/// <summary>
/// 获取系统描述
/// </summary>
/// <returns></returns>
//[HttpGet("getDesc")]
public string GetDescription(string name)
{
return _systemService.GetDescription(name);
}
}
能否路由前缀全局配置(DefaultRoutePrefix)与控制器中自定义[route("xxx")]路径同时生效。
如同时配置:
最后路径为:
实际上 Furion
底层的处理是这样的:
1、100% 和微软的行为一致
2、如果自定义了 [Route]
和 [HttpMethod]
的话,那么就以自定义为标准,不会添加任何东西进来。
话又说回来,您的需求也是合理的,也就是前缀默认情况下都应该加上去,我可以在下一个版本添加一个 ForceWithRoutePrefix
的参数,意思是强制添加默认前缀
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
已解决,将在下一个版本发布,支持两种配置:
[ApiDescriptionSettings(ForceWithRoutePrefix = true)]
using Furion.DynamicApiController;
using Microsoft.AspNetCore.Mvc;
namespace Furion.Application
{
[Route("sys"), ApiDescriptionSettings(ForceWithRoutePrefix = true)]
public class TestRouteMethod : IDynamicApiController
{
[HttpGet("getDesc")]
public string GetDescription()
{
return "Furion";
}
public string GetDescription2()
{
return "Furion";
}
}
}
{
"DynamicApiControllerSettings": {
"ForceWithRoutePrefix": true
}
}
将在 v3.4.1 版本发布
v3.4.1 版已经发布
发现点小问题,如果只定义 Route的时候,全局前缀就无效了。
只要定义一个,就可以生效了,不过方法的变量提示会丢失
这个功能就到此为止了。
因为如果你定义了 [Route]
相当于你自定义完全自定义了路由规则,asp.net core
规定只要定义了 route
,那么 action
就必须定义 [HttpMethod]
,这个功能不再继续,因为会导致和微软底层完全不兼容,也背离了 Furion
100% 兼容的原则,新版本会移除该 Issue
所有功能
另外 这个并不是丢失,而是一定你自定义了 [HttpGet]
,那么该 Action
完全交给 MVC
托管,默认生成的是 [FromQuery]
而不是 [FromPath]
,你展开即可看到。
登录 后才可以发表评论