Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need to redirect user and need requesting URL

Posted on 2011-03-15
6
Medium Priority
?
313 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
[X]
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
  • 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 2000 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 33

Assisted Solution

by:Todd Gerbert
Todd Gerbert earned 2000 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

670 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