Does the OnGet get called twice only when clicking the menu or does it also do this when you reload the Log settings page?
It is only when clicking the menu that OnGet is called twice. When reloading it is called only once.
It might occurs beacuse you have multiple routes configured for the same URL. This can cause the OnGet
method to be called twice if the routing system matches multiple routes to the URL. You should check your Startup.cs
for any route configuration that might be conflicting or creating multiple routes to the same page.
Thanks Isac. We just have a few MapControllerRoute directives for robot.txt etc. in Startup.cs, which I don't think should have any impact in this case. Just in case I commented these lines of code out, but with unchanged behavior. No, I think the weirdness is happening on the client. A peek in the Network tab under the browser's DevTools reveals that there are two requests for the same document. The first request has the following comment: "The request status cannot be shown here because the page that issued it unloaded while the request was in flight. ..."
Hmm... It works, i.e. I only get one request, if I remove all event handlers from the anchor element of my menu item. So, if I only could get a JavaScript loaded with the admin UI I would thus have a fix, albeit a very ugly one... 🤔
For the time being I've settled for a another hack: I use a lock and a (short-lived) memory cache so that the seconds request waits for the first request to generate a database result that it can reuse. It is not good solution and I don't like it, but it solves my main performance issue. 🤷♂️
I've implemented a simple menu provider that looks like this:
Behind /customadmin/logsettings is an equally simple Razor page with a PageModel that looks like this:
The two menu items specified by the menu provider are displayed as expected, but when I click on the Log Settings menu item, the OnGet() method is called twice. What could I be doing wrong?