Azure函数–;当前Azure资源名称

Azure函数–;当前Azure资源名称,azure,azure-functions,Azure,Azure Functions,如果我使用的Azure函数是TimerTrigger,那么如何在运行时获取已部署Azure资源的名称 在HttpTrigger中,您可以简单地执行以下操作:req.RequestUri.AbsoluteUri,并获得一个良好的“部署时”运行时描述 在计时器中,当TimerFunton正在执行时,如何获取Azure资源名称或路径并不明显 我想要类似于Microsoft.Azure.WebJobs.ExecutionContext的东西,它为您提供编译时函数信息–但我正在从正在运行的Azure资源中

如果我使用的Azure函数是TimerTrigger,那么如何在运行时获取已部署Azure资源的名称

在HttpTrigger中,您可以简单地执行以下操作:
req.RequestUri.AbsoluteUri
,并获得一个良好的“部署时”运行时描述

在计时器中,当TimerFunton正在执行时,如何获取Azure资源名称或路径并不明显

我想要类似于Microsoft.Azure.WebJobs.ExecutionContext的东西,它为您提供编译时函数信息–但我正在从正在运行的Azure资源中寻找一些运行时信息,该资源正在执行我的TimerRigger函数

我的退路是将Azure资源名称硬编码到环境变量中,并在运行时读取该变量。看起来很奇怪,但会起作用

谢谢你,克劳迪乌

这里是关于这一点的一些最后说明:

// Environment Variable Usage 
string res = System.Environment.GetEnvironmentVariable("WEBSITE_HOSTNAME", EnvironmentVariableTarget.Process);
//  WEBSITE_HOSTNAME is like "myAzureDeployedFuncName.azurewebsites.net" 
//  WEBSITE_HOSTNAME is like "localhost:7072" 
string res = System.Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME", EnvironmentVariableTarget.Process);
//  WEBSITE_SITE_NAME is "myAzureDeployedFuncName" on Azure 
//  WEBSITE_SITE_NAME is not there in local debug function runtime 

// using AppSettings is not the same and usign the above GetEnvironmentVariable call 
string res = System.Configuration.ConfigurationManager.AppSettings["WEBSITE_HOSTNAME"]; // not there for Settings interface
//  WEBSITE_HOSTNAME will be blank - it is not part of "Settings"
string res = System.Configuration.ConfigurationManager.AppSettings["WEBSITE_SITE_NAME"]; 
//  WEBSITE_SITE_NAME is "myAzureDeployedFuncName" on Azure when using "settings" instead of Environment variable 
//  WEBSITE_SITE_NAME is not there in local debug function runtime 
// the above AppSettings are not the same as GetEnvironmentVariable behavior at runtime 
从函数应用程序计时器触发器调用“您自己”,这是非常有用的…

网站_HOSTNAME=myAzureDeployedFuncName.azurewebsites.net

Some Other potentially useful Env Vars:
// next one has scm in name
HTTP_HOST = myAzureDeployedFuncName.scm.azurewebsites.net
// slot help
APPSETTING_WEBSITE_SLOT_NAME = Production
您可以从“WEBSITE\u SITE\u NAME”环境变量中读取

如果你去Kudu,你可以找到更多有用的变量:https://.scm.azurewebsites.net/Env.cshtml“

您可以从“WEBSITE\u SITE\u NAME”环境变量中读取


如果你去Kudu,你可以找到更多有用的变量:https://.scm.azurewebsites.net/Env.cshtml“

我实际使用了网站的主机名以适应我的情况。你的帮助和建议正是我需要知道的。我实际上使用了网站的主机名。你的帮助和建议正是我需要知道的。