Is attribute routing possible in Azure features

I am trying to provide a route parameter guidbut below error

"An exception occurred while executing the function: GetUser → One or more errors occurred. → Exception binding parameter 'req' → Invalid selection from 'System.String' to 'System.Guid'."

public static async Task<HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Admin, "get", Route = "GetUser/{userId:guid}")] HttpRequestMessage req,
            Guid userId, ILogger log)
        {
        }

The request I make is http://localhost:7071/api/GetUser/246fb962-604d-4699-9443-fa3fa840e9eb/

Am I missing something? Is it possible to use the route parameter for guidance?

+3
source share
1 answer

Invalid listing from 'System.String' to 'System.Guid'

, {userId:guid} Azure httptrigger , .

, , Guid.TryParse, Guid , .

public static string Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "GetUser/{userId:guid}")]HttpRequestMessage req, string userId, TraceWriter log)
{
    log.Info("C# HTTP trigger function processed a request.");

    Guid newGuid;

    var resmes = "";

    if (Guid.TryParse(userId, out newGuid))
    {
        resmes = "userid: " + newGuid;
    }
    else {
        resmes = "error";
    }

    return resmes;
}
+5

Source: https://habr.com/ru/post/1654236/


All Articles