Azure Functions root throws double / in route exception upon upgrading to .NET 8 and isolated
I've had an in process Azure Function project that has worked great. But with the email that went out that I need to upgrade to .NET 8 I had to also move to the isolated worker Azure Function model.
The project seems to have upgraded fine and I got it to run now after making all the additional required changes, but one problem still persists in that I cannot access the root of my project in the browser.
I've had a static page set up on the root using the "AzureWebJobsDisableHomepage": true
in local.settings.json
and "version": "2.0", "extensions": { "http": { "routePrefix": "" } }
in host.json
. But now it throws the following exception:
Microsoft.AspNetCore.Routing.Patterns.RoutePatternException: The route template separator character '/' cannot appear consecutively. It must be separated by either a parameter or a literal value.
Removing the /
from the route removes the exception, but makes the function not be run upon navigating to the address and is merely returned a HTTP 204
result.
My static web function simplified looks like this:
public class StaticWebFunctions
{
[Function(nameof(WebRoot))]
public IActionResult WebRoot([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "/")] HttpRequest request)
{
return new ContentResult() { Content = "Testing root functionality, pun intended" };
}
}
Is there a way around this limitation that was introduced?
Answers
The error you're encountering is likely due to changes in routing behavior or constraints introduced in newer versions of ASP.NET Core. The consecutive /
characters in the route template "/"
seem to be causing the issue.
To work around this limitation while still achieving your desired functionality, you can try one of the following approaches:
-
Use an empty string as the route template: Instead of
Route = "/"
, you can try using an empty string as the route template:[Function(nameof(WebRoot))] public IActionResult WebRoot([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "")] HttpRequest request) { return new ContentResult() { Content = "Testing root functionality, pun intended" }; }
This should allow the function to be triggered when navigating to the root URL.
-
Use the default route: Omit the
Route
property altogether, which will use the default route:[Function(nameof(WebRoot))] public IActionResult WebRoot([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequest request) { return new ContentResult() { Content = "Testing root functionality, pun intended" }; }
The default route should map to the root URL.
Try one of these approaches and see if it resolves the routing issue you're facing. If you still encounter issues, further investigation into the routing behavior and ASP.NET Core version differences may be necessary. Additionally, checking the Azure Functions documentation or community forums for any specific guidance related to routing changes in .NET 8 and isolated workers could be helpful.