Monday, March 26, 2012

Passing variable between asp login page and the redirected page

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

SHi All
S>
SI have an asp.net 2.0 web with a standard login control
S>
SI want to pass some extra variables to the redirected page after the
Ssuccessful login
S>
SI just can't get it to work. help much appreciated
S>
S---------------------
S------
S>
SProtected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As
SSystem.Web.UI.WebControls.AuthenticateEventArgs) Handles
SLogin1.Authenticate
S>
SContext.Items.Clear()
S>
SContext.Items.Add("UserNamevalue", Me.Login1.UserName)
S>
SContext.Items.Add("mydbkeyvalue", 2)
S>
SFormsAuthentication.RedirectFromLoginPage("steve", False)
S>
SServer.Transfer("~/memberpages/demos.aspx", True)
S>
SEnd If
S>
SCatch ex As Exception
S>
SResponse.Write(ex.Message)
S>
SEnd Try
S>
SEnd Sub
S>
S---------------------
S-------------------
S>
SIn a link button onclick event on the demos.aspx
S>
SMe.lblsamupdate.Text = "Context " &
SContext.Items("UserNamevalue").ToString
S>
SI get error 'Object reference not set to an instance of an object'
S>
SWhy???
S>
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:

Quote:

Originally Posted by

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

0 comments:

Post a Comment