SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Jun 2004
    Location
    UK
    Posts
    605
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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!

  2. #2
    Chopped Liver bronze trophy imaginekitty's Avatar
    Join Date
    Aug 2007
    Location
    Pennsyltucky
    Posts
    1,494
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    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:
    Code Csharp:
    string redirectURL = Request.QueryString["ReturnUrl"];
     if (redirectURL != null)
     {
         if (string.IsNullOrEmpty(redirectURL)){
         Response.Redirect("/");
     }
     else
     {
         Response.Redirect(redirectURL);
     }

  3. #3
    SitePoint Guru
    Join Date
    Jun 2004
    Location
    UK
    Posts
    605
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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("/");
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •