I am using an authentication attribute on some of my actions in an asp.net mvc page to refer people to a login screen if they have not authenticated. My problem is returning them to the referring page after they have logged in. I was just keeping track of the referring action and referring controller but that becomes problematic when I also need to keep track of some parameters. Is there some nifty built in trick about which I don't know?
There are two approaches used to redirect the browser window back. Approach 1: Using history. back() Method: The back() method of the window. history object is used to go back to the previous page in the current session history.
If you just want to simply go back to the previous url - just link to it with an A HREF tag. That will show you an empty form. PHP can generate redirects regardless of the web server.
The HTML Anchor Link will be assigned an OnClick event handler and when clicked, it will be redirected to the Previous Page using history. back function in JavaScript. The HTML Markup consists of an HTML Anchor Link whose HREF attribute is set to Page 2.
You should put the redirect_to to your download links if you want to redirect the user back to the previous page. You can also try this code snippet below to add in your theme's functions. php file or use Code Snippet plugin: add_action("um_after_login_fields", function(){ if( isset( $_SERVER['HTTP_REFERER'] ) && !
In case you're using FormsAuthentication, when ASP.NET redirects a user to the login page, the URL looks something like this:
http://www.mysite.com/Login?ReturnUrl=/Something
The login form's action attribute should have the same ReturnUrl parameter (either as hidden input or as part of Url) so that FormsAuthentication can pick it up and redirect, e.g.
<form action="Login?ReturnUrl=<%=Html.AttributeEncode(Request.QueryString["ReturnUrl"]) %>"></form>
or
<form><input type="hidden" name="ReturnUrl" id="ReturnUrl" value="<%=Html.AttributeEncode(Request.QueryString["ReturnUrl"])"%> /></form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With