Reputation: 23
I've implemented an Azure Function (v2 running on .Net Core 2.2) triggered by an HttpTrigger. Upon specifying either the Disable attribute or using the Application Settings ("AzureWebJobs.Function1.Disabled": "true"), I'm still able to hit this endpoint through Postman. This is ONLY happening with HttpTriggers. The ChangeFeed Triggers and QueueTriggers I am also using, are working as expected.
A few things I've tried when running locally: 1. Withing local.settings.json, I've added just the AzureWebJobs..Disabled value 2. I've added the Disable attribute 3. I've added the Disable attribute with a setting defined.
When starting up the function project, the console does show "Function Function1 is disabled."
I've tried it with my local.settings.json as such
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"AzureWebJobs.Function1.Disabled": "true"
},
"Host": {
"LocalHttpPort": 7071,
"CORS": "*"
}
}
The Function has a general format as such:
[Disable, FunctionName("Function1")]
public async Task<IActionResult> RunAsync(
[HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequest req,
Binder binder, ILogger log)
{}
I would think I would receive a 404 within Postman. Any thoughts, direction, or other information is appreciated.
Upvotes: 2
Views: 1449
Reputation: 16208
I could repro your issue as well. Despite the log saying that the function is disabled, you can still call the HTTP trigger. Looks like a bug to me. I opened an issue on Github here: https://github.com/Azure/azure-functions-host/issues/4764
Update from the github issue:
Does this only happen when running locally with the CLI (or VS)? Http requests should return 404s unless invoked via an Admin request -- this allows the portal to continue to be able to test functions. When running via the CLI, though, I believe all requests are treated as admin requests.
Yes, I can confirm this is indeed different when deployed in Azure. When I use the app setting there AND use the function key (not the master key), the call returns 404.
Upvotes: 2
Reputation: 14334
I test local and got the same result as yours, and I found it could not only disable HTTP trigger function, if disable other like Timer function simultaneously, only HTTP could run. But I test with Azure It will respond 404.
So maybe you could use host.json to disable it, actually it should say run functions you want. If you only have only one or want to disable all functions, you could set the array with null string like below code.
{
"functions": [ null ],
"version": "2.0"
}
Or like this to only run Function2 then disable Function1 :
{
"functions": [ "Function2" ],
"version": "2.0"
}
Hope this could help you.
Upvotes: 1