I am trying to create an ASP.NET MVC site that has specific areas protected by Windows Azure ACS. I want the default area to be unprotected (i.e. allow anonymous users) but only the sub areas to be protected.
I have made this happen by removing the authorization element from the system.web section in my Web.config.
<authorization>
<deny users="?" />
</authorization>
Then adding a protected location for the desired MVC3 area.
<location path="MyArea">
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</location>
However, my old code that used to access the IClaimsIdentity and pull attributes off it for processing used to live in Session_Start event of my Global.asax. Now that the site does not require authentication to access the default area, Session_Start happens without authentication taking place.
What event can I wire up to handle the authentication event of WIF?
I have implemented a sliding session timeout using SessionAuthenticationModule_SessionSecurityTokenReceived and have tried adding my user analysis logic on the OnPostAuthenticationRequest event to no avail.
I was able to get the user after first wiring up to the following event:
FederatedAuthentication.ServiceConfigurationCreated
Then within this event I wire up to this event:
FederatedAuthentication.WSFederationAuthenticationModule.SignedIn
However, within this event the session is null and session_start is never called again. So it appears the session is getting crushed when redirecting to the identity provider.
anon -> Application_start
anon -> Session_start
anon -> Navigate to /MyArea
anon -> Redirected to ACS -> Redirected to idP
anon -> Log in
auth -> Redirected to /MyArea
auth -> FederatedAuthentication.WSFederationAuthenticationModule.SignedIn occurs, but session is null!
UPDATE: I still have not found a place where both Session and Authentication exist. I am using Unity to detect the user on demand. I'd love it if there was an event that does it as it happens but my work around still works.