Change endpoint route on environment stage

Viewed 55

I have a test page which should only be available in development stage. At the moment the page will just redirect, when the environment is not set to development.

public async Task<IActionResult> OnGet()
{
    if (_environment.IsDevelopment())
    {
        await GetTestData();

        return Page();
    }

    return Redirect("/");
}

But I do not really like this approach. Is there a way to catch this on the endpoint level itself? Like a fallback?

app.UseEndpoints(endpoints =>
{
    endpoints.MapRazorPages();
    endpoints.MapFallbackToPage("/Registration");
});
1 Answers
Related