Solved

Need to redirect user and need requesting URL

Posted on 2011-03-15
6
309 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
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!

 
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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
VB.Net creating Contact in Outlook 1 49
Amazon S3 Images with .Net 3 29
Problem to copy file 14 45
Converting PHP triple des decrypt to c# 9 62
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!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

740 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