Is Attribute Routing possible in Azure Functions

泄露秘密 提交于 2019-12-04 06:41:36

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

I can reproduce same issue when use Route constraint {userId:guid} in Azure httptrigger function on my side, you can try to open an issue to give a feedback.

Besides, if possible, you can try to call Guid.TryParse method to convert the string back to Guid value in function code, the following code is for your reference.

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;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!