Redirect to querystring value on login user control

Hi,

I want to pass a querystring to a usercontrol containing the name of the URL to redirec to uplon successful log-in. I have the following code:

	protected void LogIn_OnLoggedIn(object sender, EventArgs e)
	{
		string redirectURL;
		if (Request.QueryString["redirectURL"] != null)
		{
			redirectURL = Request.QueryString["redirectURL"];
			if (string.IsNullOrEmpty(redirectURL)){
				Response.Redirect("/");
			}
			else
			{
				Response.Redirect(redirectURL);
			}
		}
	}

However, it doesn’t seem to recognise the querystring and always just redirects to the default redirect URL set in the web.config file.

The reason I need this is because the log-in form is within an iFramed modal window, so the user clicks a link from the main website, the log-in iframe is called and I then need to redirect the user to the page which they originally clicked the log-in link from.

Thanks!

By default I think the query string sets a variable called “ReturnUrl” so try Request.QueryString[“ReturnUrl”] and report back.

Also, you have Request.QueryString[“redirectURL”] twice. Why not just set it in the definition:


string redirectURL = Request.QueryString["ReturnUrl"];
 if (redirectURL != null)
 {
     if (string.IsNullOrEmpty(redirectURL)){
     Response.Redirect("/");
 }
 else
 {
     Response.Redirect(redirectURL);
 }

Thanks - yeah it’s just my syntax it seems. This works:

		string redirectURL = Request.QueryString["redirectURL"];
		if (!string.IsNullOrEmpty(redirectURL))
		{
				Response.Redirect(redirectURL);
		}
		else
		{
				Response.Redirect("/");
		}