Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Need to redirect user and need requesting URL

Posted on 2011-03-15
6
307 Views
Last Modified: 2012-05-11
When a user hits a URL from an email, say. If they are not logged in, I need to send them to the login page. Then, after succesful login, I need to navigate them the page they initially requested.

What variable do I look in to get this URL?  Or must I save the URL as a local variable, then use it at the appropriate time?

Thanks,
newbieweb
0
Comment
Question by:newbieweb
  • 3
  • 3
6 Comments
 

Author Comment

by:newbieweb
ID: 35142429
There are two distinct websites of ours. So the link will be to the second site. I need to log the return URL so when the first site gets the request, it will show the log in screen. On successful login I want to read the return URL and render that page.
0
 

Author Comment

by:newbieweb
ID: 35142470
My code can handle linking from site #2 to site #1, for login. I need to find to what variable I can attach a return URL.
0
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 500 total points
ID: 35143229
If you're using the LoginControl on site 1, you can handle it's LoggedIn event.  Check for the presence of ReturnUrl QueryString parameter, and if it starts with "http" then use Response.Redirect() to send the user there.
protected void LoginControl_LoggedIn(object sender, EventArgs e)
{
	string redirectUrl = Request.QueryString["ReturnUrl"];
	if (!String.IsNullOrEmpty(redirectUrl))
	{
		if (redirectUrl.ToLower().StartsWith("http"))
			Response.Redirect(redirectUrl);
	}
}

Open in new window


Then you can put links in the email along the lines of:
<a href="http://www.site1.com/login.aspx?ReturnUrl=http://www.site2.com/somepage.aspx">click here</a>

Open in new window


Of course, that ReturnUrl parameter should be UrlEncoded, so it would actually look like:
<a href="http://www.site1.com/login.aspx?http%3A%2F%2Fwww.site2.com%2Fsomepage.aspx">click here</a>

Open in new window

0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 33

Assisted Solution

by:Todd Gerbert
Todd Gerbert earned 500 total points
ID: 35143269
Oops, the encoded one is actually:
<a href="http://www.site1.com/login.aspx?ReturnUrl=http%3A%2F%2Fwww.site2.com%2Fsomepage.aspx">click here</a>

Open in new window


This worked in a simple test for me, but I've only got one site, so I just had it send me to www.google.com.
0
 
LVL 33

Assisted Solution

by:Todd Gerbert
Todd Gerbert earned 500 total points
ID: 35143622
Okay, setup a quick pair of web sites and configured them for cross-app authentication, and using the ReturnUrl QueryString parameter seems to work well.
0
 

Author Closing Comment

by:newbieweb
ID: 35147060
Thanks!
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question