如何解决在 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);
}
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。