Solved

Need to redirect user and need requesting URL

Posted on 2011-03-15
6
311 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 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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 …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

628 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