Passing variable between asp login page and the redirected page

Discussion in 'ASP .Net' started by Steve, Nov 1, 2007.

  1. Steve

    Steve Guest

    Hi All

    I have an asp.net 2.0 web with a standard login control

    I want to pass some extra variables to the redirected page after the successful login

    I just can't get it to work. help much appreciated

    -------------------------------------------------------------------------------------
    Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate

    Context.Items.Clear()

    Context.Items.Add("UserNamevalue", Me.Login1.UserName)

    Context.Items.Add("mydbkeyvalue", 2)

    FormsAuthentication.RedirectFromLoginPage("steve", False)

    Server.Transfer("~/memberpages/demos.aspx", True)

    End If

    Catch ex As Exception

    Response.Write(ex.Message)

    End Try

    End Sub

    ----------------------------------------------------------------------------------------------------------------------------------

    In a link button onclick event on the demos.aspx

    Me.lblsamupdate.Text = "Context " & Context.Items("UserNamevalue").ToString

    I get error 'Object reference not set to an instance of an object'



    Why?????????
     
    Steve, Nov 1, 2007
    #1
    1. Advertising

  2. Hello Steve,

    did you check that u have this variable in the context in receiver?

    ---
    WBR,
    Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

    "The greatest danger for most of us is not that our aim is too high and we
    miss it, but that it is too low and we reach it" (c) Michelangelo


    S> Hi All
    S>
    S> I have an asp.net 2.0 web with a standard login control
    S>
    S> I want to pass some extra variables to the redirected page after the
    S> successful login
    S>
    S> I just can't get it to work. help much appreciated
    S>
    S> ---------------------------------------------------------------------
    S> ----------------
    S>
    S> Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As
    S> System.Web.UI.WebControls.AuthenticateEventArgs) Handles
    S> Login1.Authenticate
    S>
    S> Context.Items.Clear()
    S>
    S> Context.Items.Add("UserNamevalue", Me.Login1.UserName)
    S>
    S> Context.Items.Add("mydbkeyvalue", 2)
    S>
    S> FormsAuthentication.RedirectFromLoginPage("steve", False)
    S>
    S> Server.Transfer("~/memberpages/demos.aspx", True)
    S>
    S> End If
    S>
    S> Catch ex As Exception
    S>
    S> Response.Write(ex.Message)
    S>
    S> End Try
    S>
    S> End Sub
    S>
    S> ---------------------------------------------------------------------
    S> -------------------------------------------------------------
    S>
    S> In a link button onclick event on the demos.aspx
    S>
    S> Me.lblsamupdate.Text = "Context " &
    S> Context.Items("UserNamevalue").ToString
    S>
    S> I get error 'Object reference not set to an instance of an object'
    S>
    S> Why?????????
    S>
     
    Michael Nemtsev, MVP, Nov 1, 2007
    #2
    1. Advertising

  3. Steve.
    I don't see how you can expect this to work:

    FormsAuthentication.RedirectFromLoginPage("steve", False)
    Server.Transfer("~/memberpages/demos.aspx", True)

    Your first line causes the browser to request the redirect page.
    the second line (Server.Transfer) will never execute.

    Also, you could either stick the items into a cookie(s) or put them in
    Session.

    -- Peter
    // Abandon all hope, ye who enter here.
    http://www.eggheadcafe.com
    unBlog: http://petesbloggerama.blogspot.com
    BlogMetaFinder: http://www.blogmetafinder.com



    "Steve" wrote:

    > Hi All
    >
    > I have an asp.net 2.0 web with a standard login control
    >
    > I want to pass some extra variables to the redirected page after the successful login
    >
    > I just can't get it to work. help much appreciated
    >
    > -------------------------------------------------------------------------------------
    > Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
    >
    > Context.Items.Clear()
    >
    > Context.Items.Add("UserNamevalue", Me.Login1.UserName)
    >
    > Context.Items.Add("mydbkeyvalue", 2)
    >
    > FormsAuthentication.RedirectFromLoginPage("steve", False)
    >
    > Server.Transfer("~/memberpages/demos.aspx", True)
    >
    > End If
    >
    > Catch ex As Exception
    >
    > Response.Write(ex.Message)
    >
    > End Try
    >
    > End Sub
    >
    > ----------------------------------------------------------------------------------------------------------------------------------
    >
    > In a link button onclick event on the demos.aspx
    >
    > Me.lblsamupdate.Text = "Context " & Context.Items("UserNamevalue").ToString
    >
    > I get error 'Object reference not set to an instance of an object'
    >
    >
    >
    > Why?????????
    >
     
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Nov 1, 2007
    #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. M O J O
    Replies:
    5
    Views:
    335
    Steven Cheng[MSFT]
    Sep 27, 2004
  2. darrel
    Replies:
    4
    Views:
    803
    darrel
    Sep 29, 2004
  3. Replies:
    2
    Views:
    350
    Guest
    Dec 22, 2006
  4. fredd00
    Replies:
    0
    Views:
    416
    fredd00
    Jul 2, 2008
  5. Irishmaninusa
    Replies:
    0
    Views:
    155
    Irishmaninusa
    Sep 23, 2004
Loading...

Share This Page