繁体   English   中英

对于特定的控制器/动作方法,有没有办法跳过 ASP.NET 核心中的 url 查询参数 urlDecoding ?

[英]Is there a way to skip the url query parameter urlDecoding in ASP.NET Core for a specific controller/action method?

我有以下 controller 方法:

public class MyApiController : Controller
{
        [HttpGet("api/custom")]
        public async Task<IActionResult> Custom(string data)
        {
        }
}

如果我使用以下查询参数 localhost:5000/api/custom?data=Y%3D%3DX 命中此操作方法,那么我会在自定义方法中获得数据参数的值Y==X

是否可以仅针对此方法禁用此解码,以便获得原始的未转义值?

对于 ASP.Net Core,如果您需要对查询参数中的字符进行编码,您可以通过这种方式使用Uri.EscapeDataString(String)

string dataEncoded = Uri.EscapeDataString(data); 

在您的HttpGet请求中,它将变为:

public class MyApiController : Controller
{
        [HttpGet("api/custom")]
        public async Task<IActionResult> Custom(string data)
        {
            string dataEncoded = Uri.EscapeDataString(data); 
        }
}

您仍然会在data参数中获得解码后的字符串。 据我所知,没有办法在特定的 controller 上完全禁用URL 解码

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM