简体   繁体   中英

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

I have the following controller method:

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

If I hit this action method with the following query param localhost:5000/api/custom?data=Y%3D%3DX then I get the value Y==X for my data parameter in the Custom method.

Is it possible to disable this decoding for this method only, so I can get the original unescaped value?

For ASP.Net Core if you need to encode the characters from a query parameter, you could use Uri.EscapeDataString(String) in this way:

string dataEncoded = Uri.EscapeDataString(data); 

In your HttpGet request it would become:

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

You will still get the decoded string in the data parameter. To my knowledge, there isn't a way to completly disable URL Decoding on a specific controller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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