I am developing a Blazor Server Side Application which I need to include cookie authentication. We created a custom login page component, but in order to create a cookie I need to call a Razor page to create the cookie.
Is there a way to call the razor page without doing a page refresh.
I tried using the UriHelper.NavigateTo but does not work with non Blazor component routes.
Then I tried with a Javascript call to do a window.location, but the issue is that this causes a browser refresh that makes all my instances to be recreated (like AppState, HttpClient), so all the information in these instances are lost (like httpclient headers, etc).
I expect to call the razor page to create a cookie, in a way that the httpclient and appstate scoped instance keep their values.
We tried the Identity scaffolding but it has a bug in the latest Preview 8
I've seen that bug, easily corrected. You can scaffold now. And otherwise,
the only problem that we have is that we could not find a way to customize the bland Login and Register pages.
maybe you could live with those 'bland pages' until the release, end of September?
The steps, based on a Preview8 server-side project with "Individual user accounts"
NB: it is a good idea to Commit-changes in Git before and after this
- temporarily disable this line in Startup:
// endpoints.MapBlazorHub<App>(selector: "app");
- run the scaffolding wizzard, add any pages you want
- uncomment the
endpoints.MapBlazorHub()
line again
- remove
Pages/_ViewStart.cshtml
- fix
Pages/Shared/_Layout.cshtml
, the first line is missing an @using
- fix
Pages/Shared/_Loginpartial.cshtml
, the second line is missing @inject
Compile and Run