Passing variable between asp login page and the redirected page

S

Steve

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?????????
 
M

Michael Nemtsev, MVP

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>
 
G

Guest

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,701
Latest member
XavierQ83

Latest Threads

Top