Brain2k

Blazor NavigationException

May 14th, 2024 (edited)
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.23 KB | Source Code | 0 0
  1. //_imports.razor
  2. @using System.Net.Http
  3. @using System.Net.Http.Json
  4. @using Microsoft.AspNetCore.Components.Authorization
  5. @using Microsoft.AspNetCore.Components.Forms
  6. @using Microsoft.AspNetCore.Components.Routing
  7. @using Microsoft.AspNetCore.Components.Web
  8. @using Microsoft.AspNetCore.Components.Web.Virtualization
  9. @using Microsoft.JSInterop
  10. @using BlazorAppIdentityDotNet8
  11. @using BlazorAppIdentityDotNet8.Client
  12. @using BlazorAppIdentityDotNet8.Components
  13. @using BlazorAppIdentityDotNet8.Data
  14. @using BlazorAppIdentityDotNet8.Data.Model
  15. @using BlazorAppIdentityDotNet8.Components.Pages.Tickets.Input
  16. @using BlazorAppIdentityDotNet8.Service.IRepo
  17. @using System.Text.RegularExpressions
  18. @using QRCoder;
  19. @using System.Drawing;
  20. @using System.IO;
  21. @using System.Net
  22. @using System.Security.Claims
  23. @using System.ComponentModel.DataAnnotations
  24. @using System.Text
  25. @using Microsoft.AspNetCore.Authentication
  26. @using Microsoft.AspNetCore.Identity
  27. @using Microsoft.AspNetCore.WebUtilities
  28. @using BlazorAppIdentityDotNet8.Identity
  29.  
  30.  
  31.  
  32.  
  33. //Login.razor
  34.  public async Task LoginUser()
  35.     {
  36.         try
  37.         {
  38.             var result = await SignInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: false);
  39.             if (result != null)
  40.                 enable = true;
  41.  
  42.             if (result.Succeeded)
  43.             {
  44.                 Logger.LogInformation("User logged in.");
  45.                 //Throw the error
  46.                 RedirectManager.RedirectTo(ReturnUrl);
  47.             }
  48.             else if (result.RequiresTwoFactor)
  49.             {
  50.                 //Throw the error
  51.                 RedirectManager.RedirectTo(
  52.                     "/Account/LoginWith2fa",
  53.                     new() { ["ReturnUrl"] = ReturnUrl, ["RememberMe"] = Input.RememberMe });
  54.             }
  55.             else if (result.IsLockedOut)
  56.             {
  57.                 Logger.LogWarning("User account locked out.");
  58.  
  59.                 //Throw the error
  60.                 RedirectManager.RedirectTo("/Account/Lockout");
  61.             }
  62.             else
  63.             {
  64.                 errorMessage = "Error: Invalid login attempt.";
  65.             }
  66.         }
  67.         catch (NavigationException ex)
  68.         {
  69.             Console.WriteLine(ex.Message);
  70.         }
  71.     }
Advertisement
Add Comment
Please, Sign In to add comment