如何获取当前的 Azure FunctionNameAttribute?
How to get the current Azure FunctionNameAttribute?
如何在函数内部以编程方式访问使用 [FunctionName("SomeFunctionName")]
设置的函数名称?
这是函数属性名称而不是方法名称。
例如:在下面的代码中,我想做类似 if (!await PermissionsHelper.userHasPermission(getCurrentFunctionAttributeName(), TokenHelper.getTokenValue(req, "oid")))
的事情
public static class GetUser
{
[FunctionName("GetUser")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "users/{id}")]
HttpRequest req,
String id,
ILogger log)
{
if (!await PermissionsHelper.userHasPermission("GetUser", TokenHelper.getTokenValue(req, "oid")))
return new UnauthorizedResult();
尝试以下操作:
public static class GetUser
{
[FunctionName("GetUser")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "users/{id}")]
HttpRequest req,
String id,
ExecutionContext executionContext,
ILogger log)
{
if (!await PermissionsHelper.userHasPermission(executionContext.FunctionName, TokenHelper.getTokenValue(req, "oid")))
return new UnauthorizedResult();
如何在函数内部以编程方式访问使用 [FunctionName("SomeFunctionName")]
设置的函数名称?
这是函数属性名称而不是方法名称。
例如:在下面的代码中,我想做类似 if (!await PermissionsHelper.userHasPermission(getCurrentFunctionAttributeName(), TokenHelper.getTokenValue(req, "oid")))
public static class GetUser
{
[FunctionName("GetUser")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "users/{id}")]
HttpRequest req,
String id,
ILogger log)
{
if (!await PermissionsHelper.userHasPermission("GetUser", TokenHelper.getTokenValue(req, "oid")))
return new UnauthorizedResult();
尝试以下操作:
public static class GetUser
{
[FunctionName("GetUser")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "users/{id}")]
HttpRequest req,
String id,
ExecutionContext executionContext,
ILogger log)
{
if (!await PermissionsHelper.userHasPermission(executionContext.FunctionName, TokenHelper.getTokenValue(req, "oid")))
return new UnauthorizedResult();