You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 6 Web API接口接收含#的userId参数时内容截断问题咨询

.NET 6 Web API接口接收含#的userId参数时内容截断问题咨询

我有一个基于.NET 6.0的Web API项目,最近在传递字符串参数时遇到了问题。

我的接口定义如下:

[HttpGet("contact/{userId}")]
public async Task<ActionResult<string>> GetUserAsync(string userId)
{
    var user = await _userService.GetUserAsync(userId);
    return user is null ? NotFound() : Ok(user);
}

当我传入带#的userId(比如example-id-#1)时,接口接收到的内容会被截断,只拿到example-id-;但如果传入不含#的字符串,就能完整接收。

我想请教两个问题:

  • 为什么Web API会截断这个参数值?
  • 如何在不修改传入值的前提下解决这个问题?

感谢解答!

备注:内容来源于stack exchange,提问作者0Neji

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.21 09:45:29