IIS will restart the site if it detects the web.config file has changed (by default).
So assuming you can programmatically read and then save that file (you don't even need to make any change), IIS will handle the rest.
This works not just in Blazor (.net core) but also .NET framework (MVC and webforms) and even classic ASP, if you really, really need to.
Probably not the "correct" way, but it is simple and works and given that this has worked for 20+ years, all the way back to classic ASP, it seems pretty robust.
I have put this in old web forms apps for years, used it many times (normally to clear caches) and never had any issue, such as mangling the web.config.