Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

How to run server side middleware before a Blazor WASM app loads

$
0
0

In our Blazor WASM app, I'm attempting to run custom middleware before the Blazor app initial loads. Basically I want to do some server side checks before the app loads, and if it doesn't pass those tests I want to throw a 404. I can't filter for / because I want this to run if somebody deep links to a page.

I'm able to get close to what I need by using this:

        app.Use(async (ctx, next) =>        {            if (!CheckIfClientExists(ctx))            {                ctx.Response.StatusCode = 404;            }            else            {                await next();            }        });

However, I don't want to run this same code on every single HTTP request; only the initial request to load the SPA. If I were manually rendering a SPA, this would be easy to add to the Index action.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>