Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return to referring page

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?

like image 366
stimms Avatar asked Oct 08 '08 03:10

stimms


People also ask

How do I redirect to the last page?

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.

How do I get my page back in PHP?

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.

How do I redirect a previous page in HTML?

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.

How do I redirect back in Wordpress?

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'] ) && !


1 Answers

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>
like image 121
liggett78 Avatar answered Sep 29 '22 22:09

liggett78