C# Azure Function is slicing '/' in URL

Viewed 53

I have Azure Function that accepts Url as parameter:

    [FunctionName(nameof(GetUrl))]
    public IActionResult GetUrl(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "url/{*url}")] HttpRequest req,
        string url)
    {
        return new OkObjectResult(HttpUtility.UrlDecode(url));
    }

I'm passing https://example.com - locally it displays "https://example.com", but on server I'm receiving "https:/example.com" (single '/'). Is there other way to solve that issue than string-replace operations?

1 Answers

For Azure Functions the catch-all in front of parameters (using a single or double asterisk) doesn't seem to have an impact on how (the value of) that parameter behaves. Also, since you're URL decoding the value yourself, adding that is not needed.

URL's cannot be passed as part of the URL path itself. You will need to add a QueryString parameter and use that one to pass in the URL Encoded value https%3a%2f%2fwww.example.com.

The call:
https://<YOUR-FUNCTION-URL>/api/url?url=https%3a%2f%2fwww.example.com

The Azure Function

public static IActionResult Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "url")] HttpRequest req,
    ILogger log)
{
    return new OkObjectResult(HttpUtility.UrlDecode(req.Query["url"]));
}

Related