- UI type: Blazor server
- DB provider: EF Core
- Tiered (MVC) or Identity Server Separated (Angular): no
- Exception message and stack trace:
- Steps to reproduce the issue:How to set the project to jump directly to the login page
12 Answer(s)
-
0
hi
You can give it a try. I think it will be works.
Like your example website, it automatically jumps to the login page.
The demo website is angular. You are using Blazor Server.
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
I am using blazor server, and I found that your example is not enough. The effect I want is that when accessing the system homepage, if there is no login, it will automatically jump to the login page. There is no need to manually click login and then jump to the login page.
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
hi
You can give it a try. I think it will be works.
Like your example website, it automatically jumps to the login page.
The demo website is angular. You are using Blazor Server.
Hi maliming,
Where the code for Angular. I also need to do like jumping to the login page. We use angular and Identity Server Separated.
Thx
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
hi pvaz
You can call
ChallengeAsyncin yourOnGetAsyncmethod ofIndexModelfor MVC tiered application.public class IndexModel : MyProjectNamePageModel { public async Task OnGetAsync() { if (!CurrentUser.IsAuthenticated) { await HttpContext.ChallengeAsync("oidc"); } } public async Task OnPostLoginAsync() { await HttpContext.ChallengeAsync("oidc"); } }Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
Hi Maliming,
thank you for your quick reply.
Perhaps my question I was not clear. When the user is not authenticated to redirect to /Account/Login.
Using your example I get:
"An unhandled exception occurred while processing the request. InvalidOperationException: No authentication handler is registered for the scheme 'oidc'. The registered schemes are: idsrv, idsrv.external, Abp.ConfirmUser, Identity.Application, Identity.External, Identity.TwoFactorRememberMe, Identity.TwoFactorUserId, Bearer, Google, Microsoft, Twitter. Did you forget to call AddAuthentication().AddSomeAuthHandler? Microsoft.AspNetCore.Authentication.AuthenticationService.ChallengeAsync(HttpContext context, string scheme, AuthenticationProperties properties)"
Thx
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
hi pvaz
I think you can redirect user to any page.
if (!CurrentUser.IsAuthenticated) { //redirect to /Account/Login }https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.controllerbase.redirect?view=aspnetcore-5.0
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
Hi,
solved this way using your advice:
var redirectUrl = UriHelper.BuildAbsolute(HttpContext.Request.Scheme, HttpContext.Request.Host, "/Account/Login"); await HttpContext.ChallengeAsync(new AuthenticationProperties { RedirectUri = redirectUrl });
return;`
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)