HttpContext.Current.User is null With IIS 7 Integrated mode..

Posted: 2012-07-03 in .Net

…even though Windows Authentication is on.

 

The simple is that you have probably moved to integrated IIS or you have called current.user too early.
Simply put you need to let IIS do a few more things first and then call the code.

Basically the first available method in global.asax.cs that you can access Current.User:
public void Application_AuthorizeRequest(object sender, EventArgs e){}

 

The pipe line can be found in this link http://learn.iis.net/page.aspx/243/aspnet-integration-with-iis/

Read on for a bit better explanation…

 

With the switch from classic to integrated mode in IIS you might be presented with a null if you have been accessing your current user from this method.
In some cases if its not null then you will have the user that IIS runs as instead, this makes it quiet hard to test as visual studio will give you your name, which is more than likely right, but when you deploy to IIS you’ll get issues.

The reason is simple, integrated mode helps strip away some of the duplicated stuff in classic. It basically brings closer the integration with asp.net to IIS, meaning that the cogs in the back end now run together and require much less duplicate work. Especialyl in areas of authentication.

With classic Asp .net kind of sits on top of IIS like a plug in or an after thought.

The pipes itself can be found in this article : http://learn.iis.net/page.aspx/243/aspnet-integration-with-iis/
skip down to Runtime Fiedlity (3 quarters of the way)
Other potential problems (like accessing the web.config too early) can also be resolved in much the same way, just move them further down the pipe so that IIS has had the chance to set what you required.

The plus side is that you can much more easily intercept, this resolves the need to access ISAPI filters and instead do what we love best and write them in code.

Cheers

Lachlan

Advertisements
Comments
  1. […] has apparently has been nullable ever since IIS Integrated Mode was available. This explains why I don’t see it in development, as I’m running IIS Express with […]

  2. […] has apparently has been nullable ever given IIS Integrated Mode was available. This explains since we don't see it in development, as I'm controlling IIS Express with […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s