Cookie not persisted w/o call to GetRedirectUrl()

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

  1. #1

    Default Cookie not persisted w/o call to GetRedirectUrl()

    I am using forms authentication. I do not have default.aspx nor do I want
    one as I am using multiple roles and I want to redirect the user after
    logging in based on his role. Here's the pertinent section from web.config:

    <authentication mode="Forms">
    <forms name="MMAuth"
    loginUrl="/forms/cl_signin.aspx"
    protection="All"
    timeout="60"
    path="/">
    </forms>
    </authentication>
    <authorization>
    <deny users="?" />
    <allow users="*" />
    </authorization>

    The below code is not my real code, but is an example I lifted from a
    website, and it should serve to pretty well illustrate my problem. I put
    into my source and compiled and debugged it. Email is a textbox with the
    user's email which serves as his user name, and let's say I've already
    validated him.

    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1,

    Email.Text,

    DateTime.Now,

    DateTime.Now.AddHours(3), // or anything else,
    it doesn't matter

    true,

    "client");
    string encryptedTicket = FormsAuthentication.Encrypt(ticket);
    HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName,
    encryptedTicket);
    cookie.Expires = ticket.Expiration; // or anything else, it doesn't matter
    Response.Cookies.Add(cookie);
    Response.Redirect(FormsAuthentication.GetRedirectU rl(Email.Text, true));

    This will persist the cookie, but I can't use this code, because
    GetRedirectUrl() is a bit stubborn and only wants to take me to
    default.aspx. According to ASP.NET Cookbook by O'Reilly, no problem, I just
    call Response.Redirect() with the page I want to go to. That will persist
    the cookie. But it doesn't.

    I find it very strange that I have to

    1) Set an expiration on the ticket
    2) Tell the ticket that is persistent
    3) Set the expiration for the cookie that contains the ticket

    and still the cookie does not persist. It seems to come back from the
    browser for the current session, but it won't persist. It will only persist
    if I

    4) call GetRedirectUrl() with the 2nd parameter set to true to let it know
    that the cookie (whose expiration I have set) which contains the ticket
    (whose expiration AND persistence flag I have set) should in fact be
    persisted on the client.

    Calling GetRedirectUrl() and tossing the return value and going on my merry
    way with Response.Redirect(), while looking very funky, would be acceptable
    at this point, but that does not work, I have to call it exactly as you see
    above.

    This is a strange API, even by Microsoft standards.

    Please help.

    Jim


    Jim Foye Guest

  2. Similar Questions and Discussions

    1. SOLVED: Can't call method "FETCH" on an undefined value at /path/to/my/Cookie.pm
      Pete Harlan posted a problem and workaround for a problem in a moderated Debian newsgroup (though this issue is not really related to Debian...
    2. FormsAuthentication.GetRedirectUrl() returns only first parameter
      It appears that FormsAuthentication.GetRedirectUrl() only returns the first parameter for the original target URL. For example, if the original...
    3. FormsAuthentication.GetRedirectUrl returns non-existing page ??
      hi, i have copied to my PC an ASP.NET project that was developed on a different PC. I have managed to create a virtual directory and build the...
    4. [PHP] Set Cookie in PHP and call with Perl
      * Thus wrote TWSC HQ (admin@twsc.co.za): How do you mean call? you want to get the value or set it? The cookie is in the headers which happens...
    5. style.display setting not persisted in viewstate
      I have <DIV> control, which has its style.display setting controlled by client-side vbscript. I have set runat = server, but the setting is not...
  3. #2

    Default Re: Cookie not persisted w/o call to GetRedirectUrl()

    Does anyone have any ideas??

    "Jim Foye" <jimfoye2@hotmail.com> wrote in message
    news:%23Lk2G$BBFHA.4004@tk2msftngp13.phx.gbl...
    >I am using forms authentication. I do not have default.aspx nor do I want
    >one as I am using multiple roles and I want to redirect the user after
    >logging in based on his role. Here's the pertinent section from web.config:
    >
    > <authentication mode="Forms">
    > <forms name="MMAuth"
    > loginUrl="/forms/cl_signin.aspx"
    > protection="All"
    > timeout="60"
    > path="/">
    > </forms>
    > </authentication>
    > <authorization>
    > <deny users="?" />
    > <allow users="*" />
    > </authorization>
    >
    > The below code is not my real code, but is an example I lifted from a
    > website, and it should serve to pretty well illustrate my problem. I put
    > into my source and compiled and debugged it. Email is a textbox with the
    > user's email which serves as his user name, and let's say I've already
    > validated him.
    >
    > FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1,
    >
    > Email.Text,
    >
    > DateTime.Now,
    >
    > DateTime.Now.AddHours(3), // or anything else, it doesn't matter
    >
    > true,
    >
    > "client");
    > string encryptedTicket = FormsAuthentication.Encrypt(ticket);
    > HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName,
    > encryptedTicket);
    > cookie.Expires = ticket.Expiration; // or anything else, it doesn't
    > matter
    > Response.Cookies.Add(cookie);
    > Response.Redirect(FormsAuthentication.GetRedirectU rl(Email.Text, true));
    >
    > This will persist the cookie, but I can't use this code, because
    > GetRedirectUrl() is a bit stubborn and only wants to take me to
    > default.aspx. According to ASP.NET Cookbook by O'Reilly, no problem, I
    > just call Response.Redirect() with the page I want to go to. That will
    > persist the cookie. But it doesn't.
    >
    > I find it very strange that I have to
    >
    > 1) Set an expiration on the ticket
    > 2) Tell the ticket that is persistent
    > 3) Set the expiration for the cookie that contains the ticket
    >
    > and still the cookie does not persist. It seems to come back from the
    > browser for the current session, but it won't persist. It will only
    > persist if I
    >
    > 4) call GetRedirectUrl() with the 2nd parameter set to true to let it know
    > that the cookie (whose expiration I have set) which contains the ticket
    > (whose expiration AND persistence flag I have set) should in fact be
    > persisted on the client.
    >
    > Calling GetRedirectUrl() and tossing the return value and going on my
    > merry way with Response.Redirect(), while looking very funky, would be
    > acceptable at this point, but that does not work, I have to call it
    > exactly as you see above.
    >
    > This is a strange API, even by Microsoft standards.
    >
    > Please help.
    >
    > Jim
    >

    Jim Foye 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