Redirecting a user (vb.net)
-
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")
-
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")
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
-
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
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!