I have a blazor wasm hosted app where a user can create an account by filling a form. When the account is created, an email is sent to the user with a link s/he must follow to confirm his/her ownership of the email address. the link points to an action method in my server. The same server hosts the blazor wasm app AND the APIs.
The problem is, when the user clicks that link, the request isn't sent to the server. Instead, blazor intercepts the call and tries to route to a page.
How can I make this work ? How can I make a link that point to an action in my server actually make it to the server when clicked ? In other words, how to bypass blazor's routing system, if possible ?
Updates:
Url.Action("actionName", "controllerName", actionParam, Request.Scheme);
. The link, for now, looks like
https://localhost:5001/api/user/confirmaemail?confirmationtoken=xyz&useremail=abc
<NotFound />
component (App.razor file) is therefore displayed.Note:
This is not an error. This is the normal behaviour of balzor wasm. If an app is hosted at www.foo.com
, then all the calls to foo.com
(www.foo.com/bar
for example) won't actually be made to foo.com
but will be intercepted by blazor and treated as routes to pages in the app. This is, however, blocking me because my APIs have the same base address as the app (the app is, for now, at localhost:5001/
and the APIs at localhost:5001/api/xyz
), hence, blazor is preventing the call to the server when I click the link. The question is how to get arround that ? And if not possible, what other options do I have to implement this flow ?
So I resolved the problem by making the Action method a GET method instead of a POST. It is quite logical when you think about it: when the user clicks the link s/he received by email, a GET will be issued, not a POST.
I Also understood that blazor routes you to a page ONLY when you enter the address in the address bar. If you click a link, the request will be issued. The reason I was thinking blazor was intercepting the request is because clicking the link was redirecting me to a page, but in fact, it was just a fallback mechanism. You can see it in the configure
methode:
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapControllers();
// the link clicked issues a GET. My action is a POST.
// So no action is found. It falls back to the index.html
// which is the entery point of my app. Blazor takes over
// from here and tries to find a page for the url requested.
endpoints.MapFallbackToFile("index.html");
});