恐怕你不能使用根路径来访问这个功能,因为https://localhost:7071/
始终是Azure功能的默认页面:
下面是我的验证步骤,我将函数的路径改为https://localhost:7071/
,但仍然显示默认页面Azure function app
.
默认情况下,您的 azure 函数的路由是localhost:7071/api/{functionName}
你现在一定已经注意到,几乎所有的函数路由都有/api/
在路线中。如果您想更改它,您可以使用以下命令修改内容来更改它host.json
.
你需要添加"extensions": { "http": { "routePrefix": "" } }
在你的 host.json 中:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensions": { "http": { "routePrefix": "" } }
}
现在,您的路线可能如下所示:
localhost:7071/{functionName}
您还需要设置Route
在代码中""
.
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "")] HttpRequest req,
当前路线应该满足您的要求:
但是用这个路径访问这个函数还是失败,所以我认为将Azure函数的路径设置为根路径是无效的,不能用它来访问你的Azure函数。
如果您部署到Azure portal
,你可以尝试添加"AzureWebJobsDisableHomepage ": true
in app settings
禁用Azure功能的主页。我在本地测试了一下,好像不行。Azure portal
似乎有效。