在 dotnet core 中获取 Azure 中 http 触发函数的当前文件夹路径

我正在 dotnet 核心中创建一个 http 触发器函数,我需要在其中找到我的项目购物示例的当前文件夹路径。虽然我能够在 vs 代码中本地执行以下代码。 私有静态只读字符串 defaultPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal),“购物样品”); 我如何在 Azure 中获取此 http 触发器功能的文件夹路径。 本地路径显示 :C:\Users\shash\Documents\shopping-samples 并且它在本地工作得很好。 请帮忙。

hbfym 回答:在 dotnet core 中获取 Azure 中 http 触发函数的当前文件夹路径

尝试以下代码获取当前文件夹路径:

using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace FunctionApp8
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous,"get","post",Route = null)] HttpRequest req,ILogger log,ExecutionContext context)
        {
            return new OkObjectResult(context.FunctionAppDirectory);
        }
    }
}
本文链接:https://www.f2er.com/339422.html

大家都在问