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

问题描述

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

解决方法

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

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);
        }
    }
}

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...