473,586 Members | 2,854 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Global.asax and HttpContext.Use r

I had a question about accessing HttpContext.Use r in global.asax. I was
trying to access HttpContext.Use r in Application_Beg inRequest() which had a
null value as opposed to containing a valid GenericPrincipa l while
accessing it from a Page_Init() method of the same application.

When does the HttpContext.Use r get initialized in the life-cycle? Why cannot
I access the same in Application_Beg inRequest() ?

Thanks
Viktor
Nov 18 '05 #1
5 10383
Are you trying to find out who is the first user to your website or will
using the Session_OnStart be enough?

Regards,

Trevor Benedict R
MCSD

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #2
you can try to access the Identity of User in the application Authtication
event

"Victor Jones" <ku*******@hotm ail.com> дÈëÏûÏ¢ÐÂÎÅ
:uu************ **@tk2msftngp13 .phx.gbl...
I had a question about accessing HttpContext.Use r in global.asax. I was
trying to access HttpContext.Use r in Application_Beg inRequest() which had a null value as opposed to containing a valid GenericPrincipa l while
accessing it from a Page_Init() method of the same application.

When does the HttpContext.Use r get initialized in the life-cycle? Why cannot I access the same in Application_Beg inRequest() ?

Thanks
Viktor

Nov 18 '05 #3
Even in Application_Aut henticate event, the HttpContext.Use r remains null,
until the request is authenticated.
"coollzh" <co*****@hotmai .com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
you can try to access the Identity of User in the application Authtication
event

"Victor Jones" <ku*******@hotm ail.com> дÈëÏûÏ¢ÐÂÎÅ
:uu************ **@tk2msftngp13 .phx.gbl...
I had a question about accessing HttpContext.Use r in global.asax. I was
trying to access HttpContext.Use r in Application_Beg inRequest() which
had a
null value as opposed to containing a valid GenericPrincipa l while
accessing it from a Page_Init() method of the same application.

When does the HttpContext.Use r get initialized in the life-cycle? Why

cannot
I access the same in Application_Beg inRequest() ?

Thanks
Viktor


Nov 18 '05 #4
I wrote a test script in the Every event that the global.asax had to
offer. Here is the sequence of events and the value of Identity.Name

Application_Sta rt - NT AUTHORITY\SYSTE M
Global_BeginReq uest - PETRA\Administr ator
Application_Beg inRequest - PETRA\Administr ator
Global_Authenti cateRequest - PETRA\Administr ator
Application_Aut henticateReques t - PETRA\Administr ator
Global_Authoriz eRequest - PETRA\Administr ator
Session_Start - PETRA\Administr ator

Except Application_Sta rt the rest of the events have the value.

Do you have the following lines in your web.config file
<authenticati on mode="Windows" />
<identity impersonate="tr ue"/>

If you do not have then this may be the reason why you are not seeing
the actual User Name. And also check if you have disabled anonymous
login. If not you will be seeing this account.

Also make sure that you Unload the application/restart IIS everytime you
make test like this or you could change the global.asax or web.config
file to automatically restart the application.

Another tip : You can SHIFT + Right click on the Internet Explorer Icon
from the Task Bar to provide different credential when testing your
application.

HTH

Trevor Benedict R
MCSD

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #5
Thanks Trevor. I was using forms authentication and my observation was a
little different from the one you had mentioned. I would assume that
HttpContext.Use r would be a GenericPrincipa l from Application_Sta rt, but it
has a null value until it reaches Application_Aut horizeRequest. Somehow, the
context variable (while using Forms Authentication) gets set between
Applicaiton_Aut henticateReques t and Application_Aut horizeRequest, which I
wanted to gain more perspective on . I see that the IIS settings are similar
to what you had mentioned and reset the IIS before the request as well. Iam
not sure why I see the difference when operated with Forms vs. Windows
authentication.

If the user's identity is anonymous, I would expect empty string for
Context.User.Id entity.Name in all events from Application_Beg inRequest,
unless Iam missing something.

Thanks
Viktor
"Trevor Benedict R" <tr********@yah oo.com> wrote in message
news:eX******** ******@TK2MSFTN GP09.phx.gbl...
I wrote a test script in the Every event that the global.asax had to
offer. Here is the sequence of events and the value of Identity.Name

Application_Sta rt - NT AUTHORITY\SYSTE M
Global_BeginReq uest - PETRA\Administr ator
Application_Beg inRequest - PETRA\Administr ator
Global_Authenti cateRequest - PETRA\Administr ator
Application_Aut henticateReques t - PETRA\Administr ator
Global_Authoriz eRequest - PETRA\Administr ator
Session_Start - PETRA\Administr ator

Except Application_Sta rt the rest of the events have the value.

Do you have the following lines in your web.config file
<authenticati on mode="Windows" />
<identity impersonate="tr ue"/>

If you do not have then this may be the reason why you are not seeing
the actual User Name. And also check if you have disabled anonymous
login. If not you will be seeing this account.

Also make sure that you Unload the application/restart IIS everytime you
make test like this or you could change the global.asax or web.config
file to automatically restart the application.

Another tip : You can SHIFT + Right click on the Internet Explorer Icon
from the Task Bar to provide different credential when testing your
application.

HTH

Trevor Benedict R
MCSD

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
6755
by: David P. Donahue | last post by:
When I wrote websites in VB .NET, I would often put functions in Global for all the pages to call. Now, in C#, doing so results in "references to non-static objects" and whatnot. I realize what that means and all, but what I'm wondering is what's the best way around it? Say, for example, I want a function that takes a username and a...
1
2468
by: Ram | last post by:
(I am running .NET Framework 1.1) I have a timer(System.Timers.Timer) running in my Global.asax page. In the timer.elapsed event I am trying to access an object I stored in the Cache. HttpContext.Current.Cache("xxx"). I am getting an error saying that HttpContext.Current is nothing. I also tried to check...
4
9168
by: Kim Bach Petersen | last post by:
I would like to record user behavior data stored in session variables. Since the data is modified throughout each session it seemed obvious to store the data when the session terminates - using Session_End in global.asax. Problem is, apparently the session-object terminating cannot be accessed from Session_End in global.asax!? What's...
7
5214
by: Ankit Aneja | last post by:
I put the code for url rewrite in my Application_BeginRequest on global.ascx some .aspx pages are in root ,some in folder named admin and some in folder named user aspx pages which are in user folder are using this code of url rewrite project is running completely fine on localhost but after uploading first page...
1
6313
by: Stu | last post by:
Hi, Im using vis studio 2003 and I think wse is out of the question as clients could be using java which doesnt support it. So I managed to find some code which allows you to develop a custom soap header called by using a http module. The problem Im having is I cannot seem to get the event to raise to fire off my authenticate method in the...
2
2335
by: tshad | last post by:
I have my error handling set up in Global.asax: Sub Application_Error(Sender As Object, E as EventArgs) In this procedure I call a function in a dll that will write out to a history file. This works for some errors, but not others. If it doesn't work, it stops there and the normal MS error page goes to the User.
0
2447
by: hynek.cihlar | last post by:
A strange behaviour thatI found in ASP.NET 2.0. I am trying to issue a callback request (handled by ICallbackEventHandler and RaiseCallbackEvent) and a regular GET request in the client browser and handle them at the same time - in parallel. The funny thing is that the behaviour of the implementation I created depends on the existence of...
1
3280
by: Anonieko | last post by:
Global.asax? Use HttpModules Instead! In a previous post, I talked about HttpHandlers - an underused but incredibly useful feature of ASP.NET. Today I want to talk about HttpModules, which are probably more common than HttpHandlers, but could still stand to be advertised a bit more. HttpModules are incredibly easy to explain, so this will...
0
1949
by: daonho | last post by:
Protected Sub Application_BeginRequest(ByVal sender As Object, ByVal e As System.EventArgs) Dim strPath As String = HttpContext.Current.Request.Path() Dim cookie As HttpCookie = HttpContext.Current.Request.Cookies("MyCookieName") ' Handle if cookie not exist If cookie Is Nothing Then ...
0
7911
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8200
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7954
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8215
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3836
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.