By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,148 Members | 759 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,148 IT Pros & Developers. It's quick & easy.

HttpContext.Current.User doesn't persist in child app

P: n/a

I am setting the HttpContext.Current.User in the
Application_AuthenticateRequest event in global.asax.cs. When I use the
IsInRole function in a web page, it works fine. So far so good. (Note that
Integrated security is used and anonymous is turned off.)

This app will actually work as a child app for an Intranet app so when I
remove the application designation in IIS for the child app folder,
IsInRole is always null, which is not good. I am thinking that httpcontext
being used is the one from the root app. Is there any way to use a
httpcontext in the child app that is set in the global.asax and can be used
anywhere?

Then I decided to use a session object to persist between requests. The
session object is not visible in the Application_AuthenticateRequest and
Application_BeginRequest events which fire every time. Session_Start is
fired only once during the creation of the session which is not suitable
for my requirement. Are there other events that fire for every request and
where session object can be used?

TIA

--
John Dalberg
Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi John:

See inline...

On Fri, 29 Apr 2005 10:10:11 -0700, John Dalberg <jo*****@hotmail.com>
wrote:

I am setting the HttpContext.Current.User in the
Application_AuthenticateRequest event in global.asax.cs. When I use the
IsInRole function in a web page, it works fine. So far so good. (Note that
Integrated security is used and anonymous is turned off.)

This app will actually work as a child app for an Intranet app so when I
remove the application designation in IIS for the child app folder,
IsInRole is always null, which is not good. I am thinking that httpcontext
being used is the one the root app.
This happens when you remove the application designation?

With the application designation ON, changes in the root application
won't be seen in the child application. These are seperate and
isolated applications with different Cache and Session collections,
etc.
Is there any way to use a
httpcontext in the child app that is set in the global.asax and can be used
anywhere?

No, to pass objects between these two applications, these two
appdomains - requires remoting. I don't think this is what you are
looking for.

Perhaps what you are looking for is a IHttpModule that can intercept
the AuthenticateRequest event and be installed in both applications?
http://msdn.microsoft.com/msdnmag/issues/02/05/asp/

Then I decided to use a session object to persist between requests. The
session object is not visible in the Application_AuthenticateRequest and
Application_BeginRequest events which fire every time. Session_Start is
fired only once during the creation of the session which is not suitable
for my requirement. Are there other events that fire for every request and
where session object can be used?


It really depends on what you need to do, but an event like
PreRequestHandlerExecute should work. Also, don't forget the Items
collection in the Context object. It won't span request but you can
shove state data into the collection and pull it out later in the
pipeline - including during Page events.

--
Scott
http://www.OdeToCode.com/blogs/scott/

Nov 19 '05 #2

P: n/a
On Fri, 29 Apr 2005 13:41:01 -0400, Scott Allen wrote:
Hi John:

See inline...

On Fri, 29 Apr 2005 10:10:11 -0700, John Dalberg <jo*****@hotmail.com>
wrote:

I am setting the HttpContext.Current.User in the
Application_AuthenticateRequest event in global.asax.cs. When I use the
IsInRole function in a web page, it works fine. So far so good. (Note that
Integrated security is used and anonymous is turned off.)

This app will actually work as a child app for an Intranet app so when I
remove the application designation in IIS for the child app folder,
IsInRole is always null, which is not good. I am thinking that httpcontext
being used is the one the root app.
This happens when you remove the application designation?

With the application designation ON, changes in the root application
won't be seen in the child application. These are seperate and
isolated applications with different Cache and Session collections,
etc.


I am not changing anything in the root application. When I removed the app
designation of the child app, the httpconext that was set in the child's
global.asax.cs seems to be null in any page in the child app. The root
application is closed source and I have no access to its global.asax.cs.
Is there any way to use a
httpcontext in the child app that is set in the global.asax and can be used
anywhere?


No, to pass objects between these two applications, these two
appdomains - requires remoting. I don't think this is what you are
looking for.


I am not passing anything between the two. I need to persist data between
pages in the child app and the session object needs to be checked in every
request. I am putting user info coming from a database in the session
object and if a setting changes in the database, it needs to go into effect
rigth away as in the next request.

The only thing shared between the root app and child app is keeping track
who logged in into the root app. The root app takes care of session
expiration but the child app needs to know who's the currently logged in
user.
Perhaps what you are looking for is a IHttpModule that can intercept
the AuthenticateRequest event and be installed in both applications?
http://msdn.microsoft.com/msdnmag/issues/02/05/asp/

Then I decided to use a session object to persist between requests. The
session object is not visible in the Application_AuthenticateRequest and
Application_BeginRequest events which fire every time. Session_Start is
fired only once during the creation of the session which is not suitable
for my requirement. Are there other events that fire for every request and
where session object can be used?


It really depends on what you need to do, but an event like
PreRequestHandlerExecute should work. Also, don't forget the Items
collection in the Context object. It won't span request but you can
shove state data into the collection and pull it out later in the
pipeline - including during Page events.


PreRequestHandlerExecute works and I am using it to save settings in the
session object. Now I have the same problem. Works fine if child app is a
standalone app but once I remove the app designation in IIS, the session is
null in the web page that's checking the session object. I figured maybe
asp.net doesn't use the Global object if the app is not configured as an
app but uses the parent's instead. I have a static method in the child's
global.asax.cs which gets used. I am not sure what is going on.
Does asp.net use only static methods from the child's global object and
everything else is from the parent's? I can't confirm this because I have
no access to the parent app's global object code.

--
John Dalberg
Nov 19 '05 #3

P: n/a
Hi John,

In a web application, Application_* means application level functionality.
It can be common for different users. Hence you can’t get any user session
related info, including SessionState and User. HttpContext.Current.User and
Session objects can be only used in Session_* method or individual pages.

HTH

Elton Wang
el********@hotmail.com

"John Dalberg" wrote:

I am setting the HttpContext.Current.User in the
Application_AuthenticateRequest event in global.asax.cs. When I use the
IsInRole function in a web page, it works fine. So far so good. (Note that
Integrated security is used and anonymous is turned off.)

This app will actually work as a child app for an Intranet app so when I
remove the application designation in IIS for the child app folder,
IsInRole is always null, which is not good. I am thinking that httpcontext
being used is the one from the root app. Is there any way to use a
httpcontext in the child app that is set in the global.asax and can be used
anywhere?

Then I decided to use a session object to persist between requests. The
session object is not visible in the Application_AuthenticateRequest and
Application_BeginRequest events which fire every time. Session_Start is
fired only once during the creation of the session which is not suitable
for my requirement. Are there other events that fire for every request and
where session object can be used?

TIA

--
John Dalberg

Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.