Solved

Need to redirect user and need requesting URL

Posted on 2011-03-15
6
303 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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 …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now