Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Redirecting a user (vb.net)

Redirecting a user (vb.net)

Scheduled Pinned Locked Moved ASP.NET
csharpdatabasequestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 8761667
    wrote on last edited by
    #1

    Hello

    I am working my way through Microsoft's WebFormsIdentity template. In the template, the login.aspx page has this:

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

          RegisterHyperLink.NavigateUrl = "Register"
        ' Enable this once you have account confirmation enabled for password reset functionality
        ' ForgotPasswordHyperLink.NavigateUrl = "Forgot"
        OpenAuthLogin.ReturnUrl = Request.QueryString("ReturnUrl")
        Dim returnUrl = HttpUtility.UrlEncode(Request.QueryString("ReturnUrl"))
        If Not \[String\].IsNullOrEmpty(returnUrl) Then
            RegisterHyperLink.NavigateUrl += "?ReturnUrl=" & returnUrl
        End If
    End Sub
    
    Protected Sub LogIn(sender As Object, e As EventArgs)
        If IsValid Then
            ' Validate the user password
            Dim manager = Context.GetOwinContext().GetUserManager(Of ApplicationUserManager)()
            Dim signinManager = Context.GetOwinContext().GetUserManager(Of ApplicationSignInManager)()
    
            ' This doen't count login failures towards account lockout
            ' To enable password failures to trigger lockout, change to shouldLockout := True
            Dim result = signinManager.PasswordSignIn(Email.Text, Password.Text, RememberMe.Checked, shouldLockout:=False)
    
            Select Case result
                Case SignInStatus.Success
                    IdentityHelper.RedirectToReturnUrl(Request.QueryString("ReturnUrl"), Response)
                    Exit Select
                Case SignInStatus.LockedOut
                    Response.Redirect("/Account/Lockout")
                    Exit Select
                Case SignInStatus.RequiresVerification
                    Response.Redirect(String.Format("/Account/TwoFactorAuthenticationSignIn?ReturnUrl={0}&RememberMe={1}",
                                                    Request.QueryString("ReturnUrl"),
                                                    RememberMe.Checked),
                                      True)
                    Exit Select
                Case Else
                    FailureText.Text = "Invalid login attempt"
                    ErrorMessage.Visible = True
                    Exit Select
            End Select
        End If
    End Sub
    

    End Class

    In that second Protected Sub under Select Case, can I comment out this line

    IdentityHelper.RedirectToReturnUrl(Request.QueryString("ReturnUrl")

    Richard DeemingR 1 Reply Last reply
    0
    • M Member 8761667

      Hello

      I am working my way through Microsoft's WebFormsIdentity template. In the template, the login.aspx page has this:

      Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

            RegisterHyperLink.NavigateUrl = "Register"
          ' Enable this once you have account confirmation enabled for password reset functionality
          ' ForgotPasswordHyperLink.NavigateUrl = "Forgot"
          OpenAuthLogin.ReturnUrl = Request.QueryString("ReturnUrl")
          Dim returnUrl = HttpUtility.UrlEncode(Request.QueryString("ReturnUrl"))
          If Not \[String\].IsNullOrEmpty(returnUrl) Then
              RegisterHyperLink.NavigateUrl += "?ReturnUrl=" & returnUrl
          End If
      End Sub
      
      Protected Sub LogIn(sender As Object, e As EventArgs)
          If IsValid Then
              ' Validate the user password
              Dim manager = Context.GetOwinContext().GetUserManager(Of ApplicationUserManager)()
              Dim signinManager = Context.GetOwinContext().GetUserManager(Of ApplicationSignInManager)()
      
              ' This doen't count login failures towards account lockout
              ' To enable password failures to trigger lockout, change to shouldLockout := True
              Dim result = signinManager.PasswordSignIn(Email.Text, Password.Text, RememberMe.Checked, shouldLockout:=False)
      
              Select Case result
                  Case SignInStatus.Success
                      IdentityHelper.RedirectToReturnUrl(Request.QueryString("ReturnUrl"), Response)
                      Exit Select
                  Case SignInStatus.LockedOut
                      Response.Redirect("/Account/Lockout")
                      Exit Select
                  Case SignInStatus.RequiresVerification
                      Response.Redirect(String.Format("/Account/TwoFactorAuthenticationSignIn?ReturnUrl={0}&RememberMe={1}",
                                                      Request.QueryString("ReturnUrl"),
                                                      RememberMe.Checked),
                                        True)
                      Exit Select
                  Case Else
                      FailureText.Text = "Invalid login attempt"
                      ErrorMessage.Visible = True
                      Exit Select
              End Select
          End If
      End Sub
      

      End Class

      In that second Protected Sub under Select Case, can I comment out this line

      IdentityHelper.RedirectToReturnUrl(Request.QueryString("ReturnUrl")

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      If you do that, I suspect the authentication cookies won't be set properly. Instead, just replace the URL you want to redirect the user to:

      IdentityHelper.RedirectToReturnUrl("~/Userpage.aspx", Response)

      However, this might annoy your users. It's standard practise for the login form to redirect them back to the page they were trying to access in the first place, instead of some other random page.


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      M 1 Reply Last reply
      0
      • Richard DeemingR Richard Deeming

        If you do that, I suspect the authentication cookies won't be set properly. Instead, just replace the URL you want to redirect the user to:

        IdentityHelper.RedirectToReturnUrl("~/Userpage.aspx", Response)

        However, this might annoy your users. It's standard practise for the login form to redirect them back to the page they were trying to access in the first place, instead of some other random page.


        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

        M Offline
        M Offline
        Member 8761667
        wrote on last edited by
        #3

        Hello Richard

        Thank you for your reply and sorry for not getting back to you earlier.

        That works a treat. The only reason the user is logging in is to upload files and that is achieved via Userpage.aspx.

        Thanks again!

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups