views:

34

answers:

2

Hi, I implemented web application (C#, ASP.NET) that, depending on customer demands, uses windows or forms authentication. Now, I need a way to execute custom code after user logs in. Code must be executed only once and should work for both types of authentication. It doesn't need to be in same place but it must execute after successful authentication.

Thanks.

A: 

I am sure ASP.NET provides OnAuthenticated events.

leppie
+1  A: 

You can handle FormsAuthentication_OnAuthenticate in Global.asax

Handling Forms Authentication Events

Boris Modylevsky
OnAuthenticate is triggered for every request. Is there event that triggers only when user state changes from unauthenticated to authenticated?
Filip
You are right, the event is triggered on every request. You can check whether user is authenticated or not using if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
Boris Modylevsky
Boris, I need to know that user just got authenticated for the first time. So this info isn't enough in my case. I can store flag in session so I know that user is already authenticated, but I would really like to use ASP.NET mechanism for this.
Filip