Csla.ApplicationContext.User.Identity.Name blank after page re-directionCsla.ApplicationContext.User.Identity.Name blank after page re-direction
Old forum URL: forums.lhotka.net/forums/t/6157.aspx
griff posted on Wednesday, January 14, 2009
Hi
I am having problems with :HttpContext.Current.User.Identity.Name and Csla.ApplicationContext.User.Identity.Name.
After logging in to my app they appear to work but once I redirect away from the page after login they are set to blank..
I have used the code from Project Tracker global.asx to populate principal/identity.
This works okay when I run locally but once the web site is copied to host provider is fails as explained. This is seriously messing up my development - due to go live soon. Can anyone shed some light on this (I am using csla principal/identity provider as opposed to asp membership provider).
Regards
GriffRockfordLhotka replied on Wednesday, January 14, 2009
Did you catch that there's code in global.asax too?
Remember that the web is stateless, so the server forgets everything between page requests. If you don't explicitly restore the principal object on each page request, it won't be there.
griff replied on Thursday, January 15, 2009
Hi
Rocky, sorry for the delay in reply. I use (I think I meant global.asax) the following code - I assume this loads on every page fetch
Protected Sub Application_AcquireRequestState( _
ByVal sender As Object, ByVal e As System.EventArgs)
Dim principal As System.Security.Principal.IPrincipal
Try
principal = _
CType(Session("CslaPrincipal"), System.Security.Principal.IPrincipal)
Catch
principal = Nothing
End Try
If principal Is Nothing Then
' didn't get a principal from Session, so
' set it to an unauthenticted PTPrincipal
ProjectTracker.Library.Security.PTPrincipal.Logout()
Else
' use the principal from Session
Csla.ApplicationContext.User = principal
End If
As I say it works fine on my pc, simply once uploaded to hosted site it appear not to work. Am I missing anything else???
RichardRockfordLhotka replied on Thursday, January 15, 2009
Hard to say without doing some debugging, etc. Are you sure Session is working properly and actually exists when this code runs?JoeFallon1 replied on Friday, January 16, 2009
We use a Session State Server.
Whenever we get weird problems like this we first check that the State Server Service is actually running on the server that we just tested the app on. Usually it is off and that is the source of the problem.
Joe
griff replied on Monday, January 19, 2009
Can you explain Session State Server. Do you mean to check whether the host server allows sessions objects - if this is what you mean then yes, as far as I can tell, session("myclassobject") works.
Richardgriff replied on Monday, January 19, 2009
Hi
Managed to sort. Global.asax code was not firing. I was using VS2008 web deployment project to deploy...this did not create global.asax file in deployment package.
I manually uploaded, still did not work, but then uploaded the App_global.asax.compiled as well and this seems to have sorted it.
Thanks
RichardCopyright (c) Marimer LLC