FormsAuthentication.RedirectFromLoginPage alternative?

Discussion in 'ASP .Net' started by Ben Fidge, Oct 22, 2004.

  1. Ben Fidge

    Ben Fidge Guest

    Is FormsAuthentication.RedirectFromLoginPage the only way to populate the
    HttpContext.Current.User.Identity.Name property?

    A base class for each page contains the follwoing property:

    public int CustomerID {
    get {
    try {
    if (HttpContext.Current.User.Identity.Name != "")
    return Convert.ToInt32(HttpContext.Current.User.Identity.Name);
    else
    return 0;
    }
    catch {
    return 0;
    }
    }
    set {
    FormsAuthentication.RedirectFromLoginPage(value.ToString(), false);
    }
    }

    Is there are more direct way of storing the ID of the logged in user,
    without invoking the "redirect from login page" functionality? I have my own
    logic for redirecting on successfull login.

    I don't use a dedicated login page, instead I have a user control on the
    right of every non-secure page, which houses login/password controls. This
    control is then dynamically replaced with another control, after a user has
    logged in and wants to visit secure pages (checkout, account details etc).

    Bascially, I want to use Forms Auhtentication without a dedicated login
    page, and without having to redirect when I set my CustomerID property to
    the ID of a given customer.

    I know this is fairly non-standard, but my client is very insistent on
    having it his way.

    Kind regards

    Ben
     
    Ben Fidge, Oct 22, 2004
    #1
    1. Advertising

  2. Ben Fidge

    Karl Seguin Guest

    You can use FormsAuthentication.SetAuthCookie(value.ToString(), false);

    You probably need to realize that the cookie won't be set until you do
    redirect/end the stream...like any good cookie...

    Would that do the trick?

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Ben Fidge" <> wrote in message
    news:...
    > Is FormsAuthentication.RedirectFromLoginPage the only way to populate the
    > HttpContext.Current.User.Identity.Name property?
    >
    > A base class for each page contains the follwoing property:
    >
    > public int CustomerID {
    > get {
    > try {
    > if (HttpContext.Current.User.Identity.Name != "")
    > return

    Convert.ToInt32(HttpContext.Current.User.Identity.Name);
    > else
    > return 0;
    > }
    > catch {
    > return 0;
    > }
    > }
    > set {
    > FormsAuthentication.RedirectFromLoginPage(value.ToString(),

    false);
    > }
    > }
    >
    > Is there are more direct way of storing the ID of the logged in user,
    > without invoking the "redirect from login page" functionality? I have my

    own
    > logic for redirecting on successfull login.
    >
    > I don't use a dedicated login page, instead I have a user control on the
    > right of every non-secure page, which houses login/password controls. This
    > control is then dynamically replaced with another control, after a user

    has
    > logged in and wants to visit secure pages (checkout, account details etc).
    >
    > Bascially, I want to use Forms Auhtentication without a dedicated login
    > page, and without having to redirect when I set my CustomerID property to
    > the ID of a given customer.
    >
    > I know this is fairly non-standard, but my client is very insistent on
    > having it his way.
    >
    > Kind regards
    >
    > Ben
    >
    >
     
    Karl Seguin, Oct 22, 2004
    #2
    1. Advertising

  3. Ben Fidge

    Ben Fidge Guest

    Cheers Karl,

    I discovered that method earlier. It also occured to me about the round-trip
    (server->client->server). I was using Server.Transfer to make use of
    Context.Items[] to pass serialized objects between pages. When I converted
    my app to use Response.Redirect it now works fine. The only caveat is that
    in order to pass objects between pages (I *hate* querystrings) I've got to
    use Session[] now.

    Thanks for the info anyway!

    Ben


    "Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
    wrote in message news:...
    > You can use FormsAuthentication.SetAuthCookie(value.ToString(), false);
    >
    > You probably need to realize that the cookie won't be set until you do
    > redirect/end the stream...like any good cookie...
    >
    > Would that do the trick?
    >
    > Karl
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/
    >
    >
    > "Ben Fidge" <> wrote in message
    > news:...
    >> Is FormsAuthentication.RedirectFromLoginPage the only way to populate the
    >> HttpContext.Current.User.Identity.Name property?
    >>
    >> A base class for each page contains the follwoing property:
    >>
    >> public int CustomerID {
    >> get {
    >> try {
    >> if (HttpContext.Current.User.Identity.Name != "")
    >> return

    > Convert.ToInt32(HttpContext.Current.User.Identity.Name);
    >> else
    >> return 0;
    >> }
    >> catch {
    >> return 0;
    >> }
    >> }
    >> set {
    >> FormsAuthentication.RedirectFromLoginPage(value.ToString(),

    > false);
    >> }
    >> }
    >>
    >> Is there are more direct way of storing the ID of the logged in user,
    >> without invoking the "redirect from login page" functionality? I have my

    > own
    >> logic for redirecting on successfull login.
    >>
    >> I don't use a dedicated login page, instead I have a user control on the
    >> right of every non-secure page, which houses login/password controls.
    >> This
    >> control is then dynamically replaced with another control, after a user

    > has
    >> logged in and wants to visit secure pages (checkout, account details
    >> etc).
    >>
    >> Bascially, I want to use Forms Auhtentication without a dedicated login
    >> page, and without having to redirect when I set my CustomerID property to
    >> the ID of a given customer.
    >>
    >> I know this is fairly non-standard, but my client is very insistent on
    >> having it his way.
    >>
    >> Kind regards
    >>
    >> Ben
    >>
    >>

    >
    >
     
    Ben Fidge, Oct 22, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TaeHo Yoo
    Replies:
    1
    Views:
    533
    Teemu Keiski
    Jul 9, 2003
  2. Lauchlan M
    Replies:
    2
    Views:
    500
    John Saunders
    Aug 17, 2003
  3. Eric Broers
    Replies:
    1
    Views:
    815
    Steve C. Orr [MVP, MCSD]
    Nov 27, 2003
  4. Jacob Crossley
    Replies:
    0
    Views:
    417
    Jacob Crossley
    Apr 2, 2004
  5. Jacob Crossley
    Replies:
    0
    Views:
    341
    Jacob Crossley
    Apr 6, 2004
Loading...

Share This Page