Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Blazor server app with authorization, after scaffold identity - logout not working #17839
In blazor server app with authorization, after scaffold identity into an MVC project with authorization, user can't logout from blazor ( LoginDisplay.razor ).
after this bad POST request :
Using this documentation.
WORKAROUND NUMBER 1:
WORKAROUND NUMBER 2:
and the orginal version with wrong behaviour
repo with sample project with workaround
Further technical details
.NET Core SDK (reflecting any global.json):
Host (useful for support):
.NET Core SDKs installed:
.NET Core runtimes installed:
@sikira have you been able to determine WHY your workaround is necessary? Without your workaround, in the scaffolded Logout.cshtml.cs, placing breakpoints everywhere shows that no code associated with this page is ever executed. Why is this? Also, a blank page is rendered (instead of the "not found" behavior), which is equally perplexing, since the framework is acknowledging that the page exists. Do you have any insight into this behavior? I'm baffled as to why OnPost() in the scaffolded Logout.cshtml.cs is not executed.
@pm64 your comment intrigued me to try to investigate more, and i find out that the issue is actually about antiforgery token. Another and better fix would be to put atribute [IgnoreAntiforgeryToken] on top of LogoutModel class in "LogOut.cshtml.cs" file. I've add this fix to orginal issue.
@MisinformedDNA could you please tell, how did you create custom login page for blazor server? I'm struggling to figure it out. I tried to just use SignInManager.PasswordSignInAsync in my form, but it seems it's for Http based authentication like in MVC projects, not for blazor.
Maybe you inherited scaffolded form somehow or used another SignInManager method?
@javiercn So it looks like what's happening here is the default Blazor Server template adds a custom LogOut.cshtml that has the
I know we have other places in the Identity scaffolder where it won't scaffold certain files if they already exist. Should we maybe implement that logic more generally? Or is there a way to align the logout logic used by Blazor Server with the default logout logic used by the default Identity UI?
I chatted with @vijayrkn and @javiercn about this. Currently when you say that you want to "Override all files" the Identity scaffolder will happily overwrite existing files. There's an important distinction here between overriding the pages in the default Identity UI, and overwriting files already on disk. Just because you said you want to override a page from the default Identity UI, does not necessarily mean that you want to overwrite an existing page that you already have. The Identity scaffolder already has support for letting you choose which pages you want to override.
It seems like it should be an error if you try to override a page that will result in an existing page getting overwritten. We could also provide an option to force overwriting files if they already exists.
The tooling could help you understand when there are existing files that would get overwritten and let you decide if you want to do that or not.