FormsAuthentication without the '?ReturnUrl' variable

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default FormsAuthentication without the '?ReturnUrl' variable

    Does anyone know if there is a way to prevent FormsAuthentication from
    adding the '?ReturnUrl' to the login page url ?

    I am always redirecting the user to a specific page upon successful
    logins.
    I *don't* wan't to redirect the user to the original page he was
    trying to access.

    I am using FormsAuthentication.SetAuthCookie followed by a
    Response.Redirect therefore, I do not need '?ReturnUrl'.

    I just think that removing this variable from the login page url makes
    it looks "cleaner" and does not lead to false expectations on behalf
    of techi users

    Thanks,

    -Itai
    Itai Guest

  2. Similar Questions and Discussions

    1. FormsAuthentication
      Hi, i am using forms authentication in an ASP.NET project I am setting the Forms authentication cookie by using:...
    2. FormsAthenticaton -- Sometimes returnurl is not set
      Hi, I have a function in my webapp that the user push a button to get a URL to the page he's on. The prupose is that the user may store the URL...
    3. BUG With FormsAuthentication
      The authentication cookie with custom user is not available or the user data is gone after a redirect. In other words all the examples on the net on...
    4. FormsAuthentication.signout does not ??
      I am using forms authentication to secure my pages. For my logout, I created a logout page with FormsAuthentication.signout is called at the...
    5. FormsAuthentication - Changes in .Net Framework 1.1!?
      I am not sure what is causing this problem but I ran into it before. I did not spend time trying to solve it since we are still working in 1.0...
  3. #2

    Default Re: FormsAuthentication without the '?ReturnUrl' variable

    There is no way to remove it that I know of, one way around it is to set the login page in web.config to an intermediate page "blah.aspx", and on that page, you redirect to the login page, which will remove the ReturnURL, it is an extra step, but it should work.

    "Itai" <itaitai2003@yahoo.com> wrote in message news:429f6e7d.0408162318.6d247adf@posting.google.c om...
    > Does anyone know if there is a way to prevent FormsAuthentication from
    > adding the '?ReturnUrl' to the login page url ?
    >
    > I am always redirecting the user to a specific page upon successful
    > logins.
    > I *don't* wan't to redirect the user to the original page he was
    > trying to access.
    >
    > I am using FormsAuthentication.SetAuthCookie followed by a
    > Response.Redirect therefore, I do not need '?ReturnUrl'.
    >
    > I just think that removing this variable from the login page url makes
    > it looks "cleaner" and does not lead to false expectations on behalf
    > of techi users
    >
    > Thanks,
    >
    > -Itai
    Raterus Guest

  4. #3

    Default Re: FormsAuthentication without the '?ReturnUrl' variable

    Thanks! but I figured out the following solution:


    /* Requires .NET Framework version 1.1 */
    /* All code in Global.asax.cs */


    // Create an event handler for the PreSendRequestHeaders event

    protected void PreSend_RequestHeaders(Object sender, EventArgs e)
    {
    string s = Response.RedirectLocation;

    // replace /login.aspx with your path
    if(s != null && s.StartsWith("http://localhost/login.aspx?ReturnUrl="))
    {
    Response.RedirectLocation ="http://localhost/login.aspx";
    }

    }


    //register the event handler

    private void InitializeComponent()
    {
    this.components = new System.ComponentModel.Container();

    // Just add this line
    this.PreSendRequestHeaders += new
    System.EventHandler(this.PreSend_RequestHeaders);
    }


    Note that on my test machine while running in debug mode I noticed
    that the event handler is called twice upon an attempt to access a
    secure path.
    The first time 'Response.RedirectLocation' contains the url with
    ‘?ReturnUrl=' and the second time it's null. I don't know why it works
    that way.
    Itai Guest

  5. #4

    Default Re: FormsAuthentication without the '?ReturnUrl' variable

    Thanks! but I figured out the following solution:


    /* Requires .NET Framework version 1.1 */
    /* All code in Global.asax.cs */


    // Create an event handler for the PreSendRequestHeaders event

    protected void PreSend_RequestHeaders(Object sender, EventArgs e)
    {
    string s = Response.RedirectLocation;

    // replace /login.aspx with your path
    if(s != null && s.StartsWith("http://localhost/login.aspx?ReturnUrl="))
    {
    Response.RedirectLocation ="http://localhost/login.aspx";
    }

    }


    //register the event handler

    private void InitializeComponent()
    {
    this.components = new System.ComponentModel.Container();

    // Just add this line
    this.PreSendRequestHeaders += new
    System.EventHandler(this.PreSend_RequestHeaders);
    }


    Note that on my test machine while running in debug mode I noticed
    that the event handler is called twice upon an attempt to access a
    secure path.
    The first time 'Response.RedirectLocation' contains the url with
    ‘?ReturnUrl=' and the second time it's null. I don't know why it works
    that way.
    Itai Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139